473,320 Members | 1,930 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.

Simple Graphics Question


I have a VB 2005 app ... main window has a picture box control (picControl)
.... I want to draw a rectangle in that control using GDI+ ... something
like:

Dim g as graphics = creategraphics|()
Dim r as Rectangle
Dim b as new system.drawing.solidbrush(system.drawing.color.red )

r.x = 100
r.y = 100
r.width = 400
r.height = 50

g.fillrectangle(b,r)

How do I get the rectangle to appear in picControl and not the basic form
itself? Somehow I would like to tell the creategraphics function that I
want to put the graphics in picControl. Can I do that?

Thanks for any help.

Mar 1 '06 #1
5 1555


Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()
hth,
Alan.

Mar 1 '06 #2
AlanT wrote:

Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()
hth,
Alan.


Do it inside the OnPaint event of the picturebox if you want it to
redraw every time the picturebox refreshes. If you do it in there you
won't have to call CreateGraphics, it'll be passed to you as the event
argument.

Dim g as graphics = e.graphics

Chris
Mar 1 '06 #3
Also, you can create a bitmap the size of the picturebox, draw your rectangle
or what ever on the bitmap then assign the bit map to the picture box image
property.
--
Dennis in Houston
"fripper" wrote:

I have a VB 2005 app ... main window has a picture box control (picControl)
.... I want to draw a rectangle in that control using GDI+ ... something
like:

Dim g as graphics = creategraphics|()
Dim r as Rectangle
Dim b as new system.drawing.solidbrush(system.drawing.color.red )

r.x = 100
r.y = 100
r.width = 400
r.height = 50

g.fillrectangle(b,r)

How do I get the rectangle to appear in picControl and not the basic form
itself? Somehow I would like to tell the creategraphics function that I
want to put the graphics in picControl. Can I do that?

Thanks for any help.

Mar 2 '06 #4
Thanks for the help ... I am (slowly) learning VB 2005 graphics. Since you
were so good at answering that question I'll ask another one! I know that
with a bitmap object I can determine the color of an individual pixel by
using the getpixel method but is there some way I can determine the color of
a particular pixel in a picture box control?

Thanks.
"Chris" <no@spam.com> wrote in mes?sage
news:u6**************@TK2MSFTNGP11.phx.gbl...
AlanT wrote:

Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()
hth,
Alan.


Do it inside the OnPaint event of the picturebox if you want it to redraw
every time the picturebox refreshes. If you do it in there you won't have
to call CreateGraphics, it'll be passed to you as the event argument.

Dim g as graphics = e.graphics

Chris

Mar 2 '06 #5
fripper wrote:
Thanks for the help ... I am (slowly) learning VB 2005 graphics. Since you
were so good at answering that question I'll ask another one! I know that
with a bitmap object I can determine the color of an individual pixel by
using the getpixel method but is there some way I can determine the color of
a particular pixel in a picture box control?

Thanks.
"Chris" <no@spam.com> wrote in mes?sage
news:u6**************@TK2MSFTNGP11.phx.gbl...
AlanT wrote:
Try using the CreateGraphics() call from the picturebox

e.g.

Dim g as graphics = Dim g As Graphics =
Me.PictureBox1.CreateGraphics()
hth,
Alan.

Do it inside the OnPaint event of the picturebox if you want it to redraw
every time the picturebox refreshes. If you do it in there you won't have
to call CreateGraphics, it'll be passed to you as the event argument.

Dim g as graphics = e.graphics

Chris



I don't know how you would do that. I believe the way you want to do
that is "draw" onto a bitmap object that is shown in the picturebox.
You should be able to find some info on drawing to a bitmap by searching
your favorite engine.

Chris
Mar 2 '06 #6

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

Similar topics

13
by: Jason Swett | last post by:
I want to do graphics with C++. Surprisingly, so far nobody has been able to tell me anything helpful. How do I do it? Any input would be greatly appreciated. Jason
1
by: Support | last post by:
Hello: Using asp.net (vb) and I dont want to use active X controls - just server side code. I have uploaded a gif file but I want to resample it to a smaller size like 100 by 100 and save it to a...
4
by: pcnerd | last post by:
I originally asked this question in the "classic" VB forum. It occured to me after I had sent it that I sent it to the wrong forum. Anyway! Here's the situation. I have VB.NET 2005 Express...
5
by: Tim | last post by:
hi I used to do this Dim gfx As System.Drawing.Graphics = pic1.CreateGraphics gfx.FillEllipse blah blah blah to draw straight onto a form. but this is frowned up (slow).
6
by: Chris Dunaway | last post by:
The method for printing documents in .Net can be confusing, especially for newer users. I would like to create a way to simplify this process. My idea would be implemented using a PrintDocument...
15
by: Hamed | last post by:
Have I posted the message to wrong newsgroup? Or Does the question is so much strage? Would someone please kindly direct me to a true newsgroup or resource? Best Regards Hamed
7
by: Delme Greening | last post by:
I have an empty project with a button on a form. What code do I need to put behind the button to draw a rectangle on my form when it is clicked?
4
by: Carsten Schmitt | last post by:
Hello, I want to draw a simple pixel (i.e. a red pixel in the center of the screen), which is always in the foreground - even when running a fullscreen application like a DirectX game. I need...
1
by: James Willmott | last post by:
If I have a question, about how to implement a graphics algorithm in C++, but not specifically related to getting the graphics on screen (that I can work out for myself). Would asking for help in...
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
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.