473,661 Members | 2,501 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(syst em.drawing.colo r.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 1576


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(syst em.drawing.colo r.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******** ******@TK2MSFTN GP11.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******** ******@TK2MSFTN GP11.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
2256
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
1321
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 file - simple ? right ? Upload -> Original.gif resample save as ->resampled.gif
4
1429
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 Edition. I have a 19" LCD monitor with the resolution set at 1280 by 1024. I want to create a graphics program, say, displaying fractals that will run with the form maximized. Are the XY coordinates on the form independent of the size & resolution of...
5
1410
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
3241
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 (much like the current model), but my PrintDocument would have a Pages collection such that each time you need to have an additional page, you would just add another page to the collection and then use the page object for the actual drawing etc. ...
15
1834
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
1736
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
3105
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 this as an easy entry for programming later a HUD, which shows several informations, like date, time, company logo, etc. Any help or just a simple code example would be appreciated.
1
1473
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 the implemention ( asking things like whether I should use std::vector vs std::list for example ) be off topic here? Thanks, jw.
0
8432
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
8343
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8855
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
8758
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8545
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7364
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
6185
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
4346
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1986
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.