473,890 Members | 1,380 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DrawLine(Pens.G reen, 0, 0, 30, 30) does not draw this time?

I created a number of pictureboxes in a panel, and want to draw lines in
those pictureboxes but I cannot. Please see the following code and make
corrections.
Thanks.

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Panel1.AutoScro ll = True
Panel1.Width = 200
Panel1.Height = 200
Dim max As Integer = 8
Dim p As PictureBox
Dim i As Integer
For i = 0 To max
p = New PictureBox
p.BorderStyle = BorderStyle.Fix edSingle
p.BackColor = Color.FromArgb( CLng(-1))
p.Top = i * (Panel1.Height - 30) + i * 10 + 10
p.Left = 10
p.Height = Panel1.Height - 32
p.Width = Panel1.Width - 32
Dim gr As Graphics = p.CreateGraphic s
gr.DrawLine(Pen s.Green, 0, 0, 30, 30)
Panel1.Controls .Add(p)
Next

'Panel1.Control s.Add(p)
'Panel1.Control s.Item(i).Top = i * (Panel1.Height - 30) + i * 10 + 10
'Panel1.Control s.Item(i).Left = 10
'Panel1.Control s.Item(i).Heigh t = Panel1.Height - 32
'Panel1.Control s.Item(i).Width = Panel1.Width - 32
'Dim gr As Graphics = Panel1.Controls .Item(i).Create Graphics
'gr.DrawLine(Pe ns.Green, 0, 0, 30, 30)

End Sub
Nov 21 '05 #1
2 3063
What you did was "correct", however nothing was rendered on the control
surface, as the control was not visible at the time. If you try adding your
panel to the controls set first, then rendering, you will probably see your
line. Also, remember that windows sends "paint" messages to a control
whenever a part of it has been trashed and needs repainting. Your line will
not be permanently etched onto the control, you will have to draw it
everytime the Paint message is received. This means overriding the paint
handlers on the control or the parent control.

"John" <Jo**@discussio ns.microsoft.co m> wrote in message
news:D1******** *************** ***********@mic rosoft.com...
I created a number of pictureboxes in a panel, and want to draw lines in
those pictureboxes but I cannot. Please see the following code and make
corrections.
Thanks.

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Panel1.AutoScro ll = True
Panel1.Width = 200
Panel1.Height = 200
Dim max As Integer = 8
Dim p As PictureBox
Dim i As Integer
For i = 0 To max
p = New PictureBox
p.BorderStyle = BorderStyle.Fix edSingle
p.BackColor = Color.FromArgb( CLng(-1))
p.Top = i * (Panel1.Height - 30) + i * 10 + 10
p.Left = 10
p.Height = Panel1.Height - 32
p.Width = Panel1.Width - 32
Dim gr As Graphics = p.CreateGraphic s
gr.DrawLine(Pen s.Green, 0, 0, 30, 30)
Panel1.Controls .Add(p)
Next

'Panel1.Control s.Add(p)
'Panel1.Control s.Item(i).Top = i * (Panel1.Height - 30) + i * 10 +
10
'Panel1.Control s.Item(i).Left = 10
'Panel1.Control s.Item(i).Heigh t = Panel1.Height - 32
'Panel1.Control s.Item(i).Width = Panel1.Width - 32
'Dim gr As Graphics = Panel1.Controls .Item(i).Create Graphics
'gr.DrawLine(Pe ns.Green, 0, 0, 30, 30)

End Sub

Nov 21 '05 #2
See the GDI+ FAQ #1 most asked question for the answer.

You'll find other articles on the use and misuse of CreateGraphics there
too.

--
Bob Powell [MVP]
Visual C#, System.Drawing

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

The GDI+ FAQ RSS feed: http://www.bobpowell.net/faqfeed.xml
Windows Forms Tips and Tricks RSS: http://www.bobpowell.net/tipstricks.xml
Bob's Blog: http://bobpowelldotnet.blogspot.com/atom.xml


"John" <Jo**@discussio ns.microsoft.co m> wrote in message
news:D1******** *************** ***********@mic rosoft.com...
I created a number of pictureboxes in a panel, and want to draw lines in
those pictureboxes but I cannot. Please see the following code and make
corrections.
Thanks.

Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Panel1.AutoScro ll = True
Panel1.Width = 200
Panel1.Height = 200
Dim max As Integer = 8
Dim p As PictureBox
Dim i As Integer
For i = 0 To max
p = New PictureBox
p.BorderStyle = BorderStyle.Fix edSingle
p.BackColor = Color.FromArgb( CLng(-1))
p.Top = i * (Panel1.Height - 30) + i * 10 + 10
p.Left = 10
p.Height = Panel1.Height - 32
p.Width = Panel1.Width - 32
Dim gr As Graphics = p.CreateGraphic s
gr.DrawLine(Pen s.Green, 0, 0, 30, 30)
Panel1.Controls .Add(p)
Next

'Panel1.Control s.Add(p)
'Panel1.Control s.Item(i).Top = i * (Panel1.Height - 30) + i * 10 + 10 'Panel1.Control s.Item(i).Left = 10
'Panel1.Control s.Item(i).Heigh t = Panel1.Height - 32
'Panel1.Control s.Item(i).Width = Panel1.Width - 32
'Dim gr As Graphics = Panel1.Controls .Item(i).Create Graphics
'gr.DrawLine(Pe ns.Green, 0, 0, 30, 30)

End Sub

Nov 21 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
41422
by: Jon Cosby | last post by:
I'm using this to draw rectangles in a PictureBox image. Not all of the rectangles are complete, and after drawing several, some of them start disapearing. What's the reason for this? Pen selPen = new Pen(Color.White); Graphics graphic = this.PicBox.CreateGraphics(); ..................
1
2732
by: Rich | last post by:
Hello, I am trying to draw a graph on a form. I can draw the box using drawline, and bars inside the box using drawrectangle, but when I try to draw a line inside the box the inner lines are not showing up. Do I need to use a property or something? Here is the code for my lines
2
3146
by: dan heskett | last post by:
I am owner-drawing a listbox, in an attempt to create a nice list with some custom "fields" and text layout. Essentially it works, but I must be missing something big, conceptually, because I get all kinds of screen artifacts and weirdness. My general goal is: list item with a few areas for text, every other item shaded a light color for readability, font color changes with selection. The listbox is populated with custom structurs...
2
2667
by: Stu | last post by:
Hi, Why does the code below only draw the last line of the loop? I was expecting this to draw 10 parallel lines. More to the piont....how do I get it to draw 10 parallel lines? Public Function GetImage() As Bitmap Dim oBitmap As Bitmap = New Bitmap(200, 200) Dim oGraphic As Graphics = Graphics.FromImage(oBitmap) Dim oPen As New Pen(Color.Black, 4)
2
7170
by: intrepid_dw | last post by:
All I am writing a C# WinForms application which is giving me some problems. The application consists of a form containing an empty Tab control to which TabPages are added dynamically (at runtime). Each TabPage contains a single Panel control. My intent is to draw a graph on that Panel control dynamically, with the code capturing a point at each update interval, then calling the Graphics.DrawLine method of the panel
1
5224
by: ssims | last post by:
I've got this code for a random GDI+ chart generator, and the demo works, but when I try to run it on my local machine I get a compiler error: Compiler Error Message: CS0117: 'Random' does not contain a definition for 'Next' Here's the code: using System; using System.Collections; using System.ComponentModel; using System.Data;
2
1191
by: Tyreec | last post by:
Hi all, I am having an issue when trying to draw a simple line. I have created a Windows Application and created a Paint method atrached to the event Paint. Inside I create a Pen and draw a line (well a point) Pen pen = new Pen( Color.Green, 1 ); e.Graphics.DrawLine( pen, 100, 100, 100, 100 ); However, when running it nothing happens and when I debug and look at the pen object I see the following:
1
1799
by: Nilam2477 | last post by:
I'm trying to draw a line on the form in C#. When i place the below draw line code in Form1_Load() method it does not draw the line when application starts. But if the same code is placed in Form1_Paint() method it works. System.Drawing.Pen myPen = new System.Drawing.Pen(System.Drawing.Color.Red, 5); System.Drawing.Graphics formGraphics = this.CreateGraphics(); formGraphics.DrawLine(myPen, 10, 10, 150, 200); Why does the code not work in...
9
2369
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of "using { Pen mypen = new Pen(Color.Black, 1)) {}), which I think makes a difference: I find the following assignment does not work: //myPenTest instantiated in the normal constructor, as was baseline,
0
9979
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11234
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9638
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
8018
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7171
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
6052
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4682
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4276
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3282
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.