Results 1 to 7 of 7

Thread: [RESOLVED] drawing a line?

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Resolved [RESOLVED] drawing a line?

    it sounds silly, but i want to have a line on a form, in vb6 i could choose a line from the toolbox and place it in the form. I can't seem to do this in c#. any help please??

    GTJ

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: drawing a line?

    You can use GDI+ to draw graphics. I mostly know VB.NET but its all similar in .NET. Or you can also use a label with its height set to the thickness you desire. Then color the background and you have a makeshift line control.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Re: drawing a line?

    cheers for the quick reply..

    good idea with the label control, but i can't get it thin enough.

    How do i use the GDI+ thing??

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: drawing a line?

    You need to import the System.Drawing namespace. Then declare a Graphics object. From there you get a method called DrawLine that takes your points and color to draw in.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: drawing a line?

    Here is one of my VB.NET examples of drawing text using GDI+. Shouldnt be too much to convert it to C#.
    VB Code:
    1. Option Explicit On
    2.  
    3. Imports System.Drawing.Drawing2D
    4.  
    5. Public Class Form1
    6.     Inherits System.Windows.Forms.Form
    7.  
    8. #Region " Windows Form Designer generated code "
    9.  
    10.     Public Sub New()
    11.         MyBase.New()
    12.         'This call is required by the Windows Form Designer.
    13.         InitializeComponent()
    14.         'Add any initialization after the InitializeComponent() call
    15.     End Sub
    16.  
    17.     'Form overrides dispose to clean up the component list.
    18.     Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
    19.         If disposing Then
    20.             If Not (components Is Nothing) Then
    21.                 components.Dispose()
    22.             End If
    23.         End If
    24.         MyBase.Dispose(disposing)
    25.     End Sub
    26.  
    27.     'Required by the Windows Form Designer
    28.     Private components As System.ComponentModel.IContainer
    29.  
    30.     'NOTE: The following procedure is required by the Windows Form Designer
    31.     'It can be modified using the Windows Form Designer.  
    32.     'Do not modify it using the code editor.
    33.     Friend WithEvents rtbCanvas As System.Windows.Forms.RichTextBox
    34.     Friend WithEvents btnDrawMe As System.Windows.Forms.Button
    35.     <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
    36.         Me.rtbCanvas = New System.Windows.Forms.RichTextBox
    37.         Me.btnDrawMe = New System.Windows.Forms.Button
    38.         Me.SuspendLayout()
    39.         '
    40.         'rtbCanvas
    41.         '
    42.         Me.rtbCanvas.Location = New System.Drawing.Point(24, 20)
    43.         Me.rtbCanvas.Name = "rtbCanvas"
    44.         Me.rtbCanvas.Size = New System.Drawing.Size(244, 196)
    45.         Me.rtbCanvas.TabIndex = 0
    46.         Me.rtbCanvas.Text = ""
    47.         '
    48.         'btnDrawMe
    49.         '
    50.         Me.btnDrawMe.Location = New System.Drawing.Point(188, 228)
    51.         Me.btnDrawMe.Name = "btnDrawMe"
    52.         Me.btnDrawMe.TabIndex = 1
    53.         Me.btnDrawMe.Text = "Draw Me"
    54.         '
    55.         'Form1
    56.         '
    57.         Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
    58.         Me.ClientSize = New System.Drawing.Size(292, 266)
    59.         Me.Controls.Add(Me.btnDrawMe)
    60.         Me.Controls.Add(Me.rtbCanvas)
    61.         Me.Name = "Form1"
    62.         Me.Text = "Form1"
    63.         Me.ResumeLayout(False)
    64.  
    65.     End Sub
    66.  
    67. #End Region
    68.  
    69.     Private Sub btnDrawMe_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnDrawMe.Click
    70.         Dim br As New SolidBrush(Color.Red)
    71.         Dim ft As New Font("Arial", 12, FontStyle.Italic Or FontStyle.Bold)
    72.         Me.rtbCanvas.CreateGraphics.DrawString("RobDog888 w00t! :D", ft, br, Me.rtbCanvas.Left + 10, Me.rtbCanvas.Top + 10)
    73.         br.Dispose()
    74.         ft.Dispose()
    75.     End Sub
    76.  
    77. End Class
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  6. #6
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: drawing a line?

    You can set the height of the label in its properties window to 1 pixel or 2. Easier then resizing as the snap to grid may cause it to increase or decrease by 4-8 pixels.
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2005
    Location
    England
    Posts
    283

    Re: drawing a line?

    o yer got it cheers...

    GTJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width