473,783 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PictureBox & GDI

Lou
I have a picture box with an image loaded into it from an Image list (Its a
solid Black Image).
Next I draw some lines into the picture box.

The resulting image with the lines is NOT the return value of
PictureBox1.Ima ge????
In the exapmle below control "D" shows only the picture(Black Image) without
the lines I added using the brush?
The Picturebox shows the lines nicely but the lines don't seem to be part of
the controls "Inage" property.
How can I get the lines into my control "D"

-Lou

'Draw lines in the picturebox

'============== =============== =============

Dim m_Brush As Brush

Dim myGraphics As Graphics

Dim m_Color1 As Color = Color.Blue

' Create a solid brush based on selected color

Dim mySolidBrush As New SolidBrush(m_Co lor1)

' Set m_Brush equal to the newly created brush

m_Brush = mySolidBrush

Dim myPen As New Pen(m_Brush, 2)

' Use the brush to draw the appropriate Drawing in the PictureBox1

myGraphics = PictureBox1.Cre ateGraphics()

' draw the safe title

myGraphics.Draw Line(myPen, 10, 0, 10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, 10, PictureBox1.Wid th, 10)

myGraphics.Draw Line(myPen, PictureBox1.Wid th - 10, 0, PictureBox1.Wid th -
10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, PictureBox1.Hei ght - 10, PictureBox1.Wid th,
PictureBox1.Hei ght - 10)

'============== =============== ==============

D.Picture = PictureBox1.Ima ge
Nov 23 '05 #1
8 2400
Lou wrote:
I have a picture box with an image loaded into it from an Image list (Its a
solid Black Image).
Next I draw some lines into the picture box.

The resulting image with the lines is NOT the return value of
PictureBox1.Ima ge????
In the exapmle below control "D" shows only the picture(Black Image) without
the lines I added using the brush?
The Picturebox shows the lines nicely but the lines don't seem to be part of
the controls "Inage" property.
How can I get the lines into my control "D"

-Lou

'Draw lines in the picturebox

'============== =============== =============

Dim m_Brush As Brush

Dim myGraphics As Graphics

Dim m_Color1 As Color = Color.Blue

' Create a solid brush based on selected color

Dim mySolidBrush As New SolidBrush(m_Co lor1)

' Set m_Brush equal to the newly created brush

m_Brush = mySolidBrush

Dim myPen As New Pen(m_Brush, 2)

' Use the brush to draw the appropriate Drawing in the PictureBox1

myGraphics = PictureBox1.Cre ateGraphics()

' draw the safe title

myGraphics.Draw Line(myPen, 10, 0, 10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, 10, PictureBox1.Wid th, 10)

myGraphics.Draw Line(myPen, PictureBox1.Wid th - 10, 0, PictureBox1.Wid th -
10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, PictureBox1.Hei ght - 10, PictureBox1.Wid th,
PictureBox1.Hei ght - 10)

'============== =============== ==============

D.Picture = PictureBox1.Ima ge

You will need to change the underlying bitmap image to do what you want.
You are actually just drawing on top of the image control by using
drawline.

Take a look at this example. It should get you on your way:
http://www.vbdotnetheaven.com/Code/Jun2003/2058.asp

Good Luck
Chris
Nov 23 '05 #2
"Lou" <lo********@com cast.net> schrieb:
I have a picture box with an image loaded into it from an Image list (Its a
solid Black Image).
Next I draw some lines into the picture box.

The resulting image with the lines is NOT the return value of
PictureBox1.Ima ge????
In the exapmle below control "D" shows only the picture(Black Image)
without the lines I added using the brush?
The Picturebox shows the lines nicely but the lines don't seem to be part
of the controls "Inage" property.
How can I get the lines into my control "D"


<URL:http://www.dotnetrix.c o.uk/misc.html>
-> "Save the Image currently displayed in a PictureBox."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #3
Lou
I just tried that code and it doesn't save the lines I added to the Picture
box, it only saves the image??
I stepped throgh the code
-Lou
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:eb******** *****@TK2MSFTNG P15.phx.gbl...
"Lou" <lo********@com cast.net> schrieb:
I have a picture box with an image loaded into it from an Image list (Its
a solid Black Image).
Next I draw some lines into the picture box.

The resulting image with the lines is NOT the return value of
PictureBox1.Ima ge????
In the exapmle below control "D" shows only the picture(Black Image)
without the lines I added using the brush?
The Picturebox shows the lines nicely but the lines don't seem to be part
of the controls "Inage" property.
How can I get the lines into my control "D"


<URL:http://www.dotnetrix.c o.uk/misc.html>
-> "Save the Image currently displayed in a PictureBox."

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #4
"Lou" <lo********@com cast.net> schrieb:
I just tried that code and it doesn't save the lines I added to the Picture
box, it only saves the image??
I stepped throgh the code


The sample will only work if you are drawing the lines in the control's
overridden 'OnPaint' method or 'Paint' event handler.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #5
Lou
Yup its there, but it still saves w/o my lines that I do see in the PB

Private Sub PictureBox1_Pai nt(ByVal sender As Object, ByVal e As
System.Windows. Forms.PaintEven tArgs) Handles PictureBox1.Pai nt

'============== =============== =============

Dim m_Brush As Brush

Dim myGraphics As Graphics

Dim m_Color1 As Color = Color.Blue

' Create a solid brush based on selected color

Dim mySolidBrush As New SolidBrush(m_Co lor1)

' Set m_Brush equal to the newly created brush

m_Brush = mySolidBrush

Dim myPen As New Pen(m_Brush, 2)

' Use the brush to draw the appropriate Drawing in the PictureBox1

myGraphics = PictureBox1.Cre ateGraphics()

' draw the safe title

myGraphics.Draw Line(myPen, 10, 0, 10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, 10, PictureBox1.Wid th, 10)

myGraphics.Draw Line(myPen, PictureBox1.Wid th - 10, 0, PictureBox1.Wid th -
10, PictureBox1.Hei ght)

myGraphics.Draw Line(myPen, 0, PictureBox1.Hei ght - 10, PictureBox1.Wid th,
PictureBox1.Hei ght - 10)

'============== =============== ==============

End Sub

"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:Oj******** ******@tk2msftn gp13.phx.gbl...
"Lou" <lo********@com cast.net> schrieb:
I just tried that code and it doesn't save the lines I added to the
Picture box, it only saves the image??
I stepped throgh the code


The sample will only work if you are drawing the lines in the control's
overridden 'OnPaint' method or 'Paint' event handler.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #6
"Lou" <lo********@com cast.net> schrieb:
myGraphics = PictureBox1.Cre ateGraphics()


=> 'myGraphics = e.Graphics'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Nov 23 '05 #7
Lou
oops...
Thanks.
Thats what I get when I cut and paste..
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u4******** ********@tk2msf tngp13.phx.gbl. ..
"Lou" <lo********@com cast.net> schrieb:
myGraphics = PictureBox1.Cre ateGraphics()


=> 'myGraphics = e.Graphics'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #8
Lou
It all works well except when I try to save the bitmap the second time, the
savefile function crashes on the
bmp.save
seems the dispose function doesn't release the file and when you try to
save again it crashes.
Something keeps the file open?
any ideas?
"Herfried K. Wagner [MVP]" <hi************ ***@gmx.at> wrote in message
news:u4******** ********@tk2msf tngp13.phx.gbl. ..
"Lou" <lo********@com cast.net> schrieb:
myGraphics = PictureBox1.Cre ateGraphics()


=> 'myGraphics = e.Graphics'.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>

Nov 23 '05 #9

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

Similar topics

4
28197
by: Ed Landau | last post by:
In VB6.0, I can put an image on a form and assign it's .picture property at run-time. In VBA (within MS Access), when I put down an image control on a form, it asks me for the source to the image (at design-time). Why? Why can't I find PictureBox in VBA within MS Access? And most importantly...why can't I put either in a Report within MS Access? What I really want is to be able to display pictures in an MS Access report (pictures...
0
1954
by: Tim Bücker | last post by:
Hello. I want to render in a picturebox (pbD3DSurface) using DirectDraw. This is working more or less but the coordinates are always screen oriented and not pictureBox oriented. x = 10; //+this.Location.X+this.pbD3DSurface.Location.X; y = 10; //+this.pbD3DSurface.Location.Y+this.Location.Y; back.DrawCircle(x, y, 5); //back = surface
0
3884
by: akh | last post by:
I want to use de Drag and Drop ´s event to move a picture box from a form and within a Picture Box. But I have behaviour if the MyPBox As PictureBox as the Globale varible or not Thanks for your help, Here is the code.
3
63439
by: Tom | last post by:
I have a picturebox on my VB.NET form. The picturebox size mode is set to stretched. I then load an image into that form and display it. As the user moves the mouse over the form, I want to get and display (in the status bar) the image coordinates of the mouse location. However, if I use the picturebox's MouseMove event, I am getting the coordinates of the mouse over the PICTUREBOX, not the actual image underneath that (which is stretched)....
1
1426
by: The Confessor | last post by:
(ellipses in place of code sections which do not deviate from defaults) Private Sub Form_Main_Load(...) Handles MyBase.Load For A = 0 To 16 For B = 0 To 14 PictureBox_MapEditor_Map.CreateGraphics.DrawImage (System.Drawing.Image.FromFile("C:\The RPG Project\Test 2.bmp"), A * 40, B * 40) Next Next
2
2204
by: the_grove_man | last post by:
Let's say i have a tab control. And on one of the tabs is a fully docked picture box with an image. I also have a few groupboxes on top of this picture box. How can I make the background image of the groupboxes fit into what is on the picturebox.
1
8483
by: John Devlon | last post by:
Hi, Does anyone know how to assign an image from an imagelist to a picturebox ? How do dynamicly change the picture to another image of the imagelist ? Thanx John
4
3820
by: munibe | last post by:
Hi, i have a problem about picturebox control. if you may help me, i will be so happy. i have a picturebox named pic_map, and i added a button named customer_button, my wish is to add a new small picturebox on the map_picture and the new added picturebox should have click event to get the location of it when it is clicked. i have written some code in C# but when clicking the small picturebox it just gets the location of the last added one,...
5
5380
by: AWW | last post by:
XP VB 2005 running an example from help that creates a picturebox in code - the picturebox is not created. If I comment out the "Dim Box as New PictureBox" and create it in Design mode - the example works. I have tried Show, Enabled, Visible, and even BackColor. Why does a help example not work? and why does Design creation work? Thanks - I hope.
0
9643
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
9480
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
10313
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
10147
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...
0
9946
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8968
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...
0
5511
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3643
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2875
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.