473,320 Members | 1,732 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

CreateGraphics help in VB.net

Hello,

I'm an amateur in VB6, and I just switched to VB.Net (2003) .
However, I've never used graphicals functions in neither those
language... (Last time I drew something was in VB6).

I just tried the following code and it is not working properly:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim g As Graphics = Form1.CreateGraphics
Dim myPen As New Pen(Color.Red)
myPen.Width = 5
g.DrawLine(myPen, 1, 1, 45, 65)
End Sub

I get the error: "Reference to a non-shared member requires an object
reference."; I don't understand what it means.

I can replace the first line with:
Dim g As Graphics = Me.CreateGraphics
and it works... But I'd like to specify directly the Form1. (I must
also confess I don't perfectly understand the use of the "ME"
keyword...)

Any help would be appreciated.

Thank you.

Dec 28 '07 #1
3 5327
"Me" is the way to go. Use it.

Lose the idea that "Form1" "Form2" refer to instantiated objects. The error
message is pretty clear if you think about it. In VB.NET "Form1" doesn't
refer to an object. It refers to a Type.

<br**************@yahoo.comwrote in message
news:ee**********************************@e10g2000 prf.googlegroups.com...
Hello,

I'm an amateur in VB6, and I just switched to VB.Net (2003) .
However, I've never used graphicals functions in neither those
language... (Last time I drew something was in VB6).

I just tried the following code and it is not working properly:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim g As Graphics = Form1.CreateGraphics
Dim myPen As New Pen(Color.Red)
myPen.Width = 5
g.DrawLine(myPen, 1, 1, 45, 65)
End Sub

I get the error: "Reference to a non-shared member requires an object
reference."; I don't understand what it means.

I can replace the first line with:
Dim g As Graphics = Me.CreateGraphics
and it works... But I'd like to specify directly the Form1. (I must
also confess I don't perfectly understand the use of the "ME"
keyword...)

Any help would be appreciated.

Thank you.
Dec 29 '07 #2
P.S.
This might help alot concerning "Me."

Also, I highly recommend this book to Classic VB coders... written by Dan
Appleman (the old VB.Classic Guru) . It helped me A LOT when I was moving to
..NET from VB6.
http://desaware.com/products/books/n...net/index.aspx
"CMoya" <mo*@nospam.comwrote in message
news:CC**********************************@microsof t.com...
"Me" is the way to go. Use it.

Lose the idea that "Form1" "Form2" refer to instantiated objects. The
error message is pretty clear if you think about it. In VB.NET "Form1"
doesn't refer to an object. It refers to a Type.

<br**************@yahoo.comwrote in message
news:ee**********************************@e10g2000 prf.googlegroups.com...
>Hello,

I'm an amateur in VB6, and I just switched to VB.Net (2003) .
However, I've never used graphicals functions in neither those
language... (Last time I drew something was in VB6).

I just tried the following code and it is not working properly:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim g As Graphics = Form1.CreateGraphics
Dim myPen As New Pen(Color.Red)
myPen.Width = 5
g.DrawLine(myPen, 1, 1, 45, 65)
End Sub

I get the error: "Reference to a non-shared member requires an object
reference."; I don't understand what it means.

I can replace the first line with:
Dim g As Graphics = Me.CreateGraphics
and it works... But I'd like to specify directly the Form1. (I must
also confess I don't perfectly understand the use of the "ME"
keyword...)

Any help would be appreciated.

Thank you.
Dec 29 '07 #3
CMoya is correct regarding the form object. VB 6 had a hidden way of using
Form1 as an instance.

To add what CMoya said, I think that once past that issue, you will have
trouble with your direction. Drawing graphics should be done on the paint
methods of the form. You are bound to run into problems trying to draw in a
button click. Instead, you should look into handling the form's paint event,
and when the button is clicked, set some parameter that determines how you
paint handler will behave. MSDN has an example at
http://msdn2.microsoft.com/en-us/lib...nt(VS.80).aspx.
"br**************@yahoo.com" wrote:
Hello,

I'm an amateur in VB6, and I just switched to VB.Net (2003) .
However, I've never used graphicals functions in neither those
language... (Last time I drew something was in VB6).

I just tried the following code and it is not working properly:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim g As Graphics = Form1.CreateGraphics
Dim myPen As New Pen(Color.Red)
myPen.Width = 5
g.DrawLine(myPen, 1, 1, 45, 65)
End Sub

I get the error: "Reference to a non-shared member requires an object
reference."; I don't understand what it means.

I can replace the first line with:
Dim g As Graphics = Me.CreateGraphics
and it works... But I'd like to specify directly the Form1. (I must
also confess I don't perfectly understand the use of the "ME"
keyword...)

Any help would be appreciated.

Thank you.

Dec 29 '07 #4

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

Similar topics

4
by: RickDee | last post by:
I really can't understand on how to use CreateGraphics. Even though I have follow what is shown in many sites, I can't get it working at all. For example. I have textbox name textbox1. I...
1
by: S Domadia | last post by:
hi, now actually i want to design custom combo in which combo's button (in which down arrow is there to perform clicking for dropdown type of combo) should be also black in color. so as it's not...
1
by: JH | last post by:
I have a tab control in my form. I am trying to create a dynamic pie chart. If I use the following code,it works fine on the main form. this.CreateGraphics().FillPie(brushtargeted,240,200,200, 200,...
1
by: takilroy | last post by:
Hi, I am trying to implement this snippet of code from the .Net help documentatiion so that I can modify the width of a textbox on one of my aspx forms. However, for some reason visual studio...
11
by: active | last post by:
picInfo is a PictureBox that I write into when the mouse moves. Below is a snip of the code. The text flashes on the screen but does not stay there. Anyone know why? Second question.-...
6
by: saunderl | last post by:
Hello Everyone, I'm trying to just play with managed VC++. I just want to draw a box on the form when it is clicked. Here is my click event handler System::Void Test_Click(System::Object^ ...
8
by: pigeonrandle | last post by:
Hi, Please pity me, i am on a dial-up connection for the first time in 5 years :( ! Does anyone know how the resulting Graphics objects differ ...? What i really mean is can someone explain it...
6
by: active | last post by:
I did the following and then wondered it's good practice. Me.CreateGraphics.DrawImage(Img, 0, 0) I'm thinking about disposing the Graphics object. A couple of lines after this I exit the sub...
4
by: vijay_3491 | last post by:
Hi, How to write a CreateGraphics method for a class similar to form.CreateGraphics()? Pls help. Thanks in Advance.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.