2009-03-28 6 views
-1

que je fais des applications Windows en VB.NET 2005. Je veux utiliser dans mon projet graphique. J'ai déjà posé cette question sur ce site. Mais les téléspectateurs ont dit la solution d'utiliser "MSChartControl" (mais c'est pour Visual Studio 2008.). Existe-t-il un autre moyen de créer un graphique dans notre propre code (sans utiliser la DLL d'un tiers?). Aide aimable nécessaire. Merci d'avance.est-il une autre façon de créer graphique en VB.NET 2005 ou C# .NET 2005

Sivakumar.P

+0

choix intéressant de mise en forme! –

+0

Duplicata de http://stackoverflow.com/questions/684493/how-to-create-chart-in-vb-net-or-c-net-for-windows-applications par le même utilisateur –

Répondre

2

Vous pouvez dessiner un vous-même en utilisant des méthodes de l'objet System.Drawing.Graphics. Cela peut être fait directement dans l'événement/override OnPaint du formulaire ou encapsulé dans un composant/contrôle séparé.

Public Class Form1 
Protected Overrides Sub OnCreateControl() 
    MyBase.OnCreateControl() 
    SetStyle(ControlStyles.ResizeRedraw, True) 
End Sub 
Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs) 
    MyBase.OnPaint(e) 

    With e.Graphics 
    .DrawLines(SystemPens.WindowText, New Point() { _ 
       New Point(60, 0), _ 
       New Point(60, ClientRectangle.Bottom - 60), _ 
       New Point(ClientRectangle.Right, ClientRectangle.Bottom - 60)}) 
    For y = 0 To 100 Step 15 
     Dim wid = e.Graphics.MeasureString(y.ToString, Font).Width 
     .DrawString(y.ToString, Font, SystemBrushes.WindowText, 60 - wid, CSng(ClientRectangle.Bottom - 60 - (y * (ClientRectangle.Size.Height - 60)/100))) 
    Next 

    Dim sf As New System.Drawing.StringFormat(System.Drawing.StringFormatFlags.DirectionVertical) 
    For x = 0 To 5 
     Dim dateStr = DateTime.Today.AddDays(x).ToShortDateString() 
     Dim xCoord As Integer = CInt(60 + (ClientSize.Width - 60) * (x + 0.5)/6) 
     Dim yBottom As Integer = ClientRectangle.Bottom - 60 
     .DrawString(dateStr, Font, SystemBrushes.WindowText, xCoord, yBottom, sf) 
     Dim yTop As Integer = CInt(yBottom - (CInt(Date.Today.AddDays(x).DayOfWeek) + 2) * (ClientSize.Height - 60)/10) 
     Dim bar As Rectangle = New Rectangle(xCoord, yTop, 18, yBottom - yTop) 
     .FillRectangle(Brushes.LightBlue, bar) 
     .DrawRectangle(SystemPens.WindowText, System.Drawing.Rectangle.Round(bar)) 
    Next 
    End With 
End Sub 
End Class 
+0

Pouvez-vous donner un exemple? S'il vous plaît – sivakumar

+0

OK, j'ai ajouté un exemple de code très simple qui dessine un graphique directement sur un formulaire. Bien sûr, vous voudriez avoir plus de variables et de procédures pour le rendre plus flexible, mais cela montre comment dessiner des graphiques qui ressemblent à un graphique. – BlueMonkMN

0

Votre probablement mieux avec ZedGraph plutôt que la croissance de votre propre.

Questions connexes