Re: Drawing a string

From: Peter Foot [MVP] (feedback_at_no-spam.inthehand.com)
Date: 09/24/04


Date: Fri, 24 Sep 2004 14:29:39 +0100

No, why don't you ditch the picturebox and do all the painting in the
OnPaint method of your form, get the graphics object you are passed, draw
the image then the text

Peter

-- 
Peter Foot
Windows Embedded MVP
www.inthehand.com | www.opennetcf.org
Do have an opinion on the effectiveness of Microsoft Windows Mobile and
Embedded newsgroups?  Let us know!
https://www.windowsembeddedeval.com/community/newsgroups
"Cyberdot" <Cyberdot@discussions.microsoft.com> wrote in message 
news:D5B6DEA5-B5D2-4B89-991C-F29C1EF1AF8F@microsoft.com...
> Yeah, I tried it and it works. But now I have another problem. I have a
> picturebox on the same position where I want to draw the string, and it 
> looks
> like the picture box is in front of the string I've drawn. Is there a 
> method
> to get the graphics handler for a picturebox?
>
> Thx,
> Cyberdot
>
> "Peter Foot [MVP]" wrote:
>
>> Because you haven't instantiated g, just created a variable to hold a
>> Graphics object. You can use
>>
>> g = Me.CreateGraphics()
>>
>> To get the Graphics instance for your form, which you will then be able 
>> to
>> draw with. You would probably be best to add this drawing code into your
>> OnPaint override for the form, then invalidate the form when the value
>> changes.
>>
>> Peter
>>
>> -- 
>> Peter Foot
>> Windows Embedded MVP
>> www.inthehand.com | www.opennetcf.org
>>
>> Do have an opinion on the effectiveness of Microsoft Windows Mobile and
>> Embedded newsgroups?  Let us know!
>> https://www.windowsembeddedeval.com/community/newsgroups
>>
>> "Cyberdot" <Cyberdot@discussions.microsoft.com> wrote in message
>> news:44F9F156-0629-4DA3-B0D7-CFEAFA40DD51@microsoft.com...
>> > Hello,
>> > I've got a little problem. I want to draw a string to my form with the
>> > follówing code:
>> >
>> >    Public Sub titleSetTime(ByVal newTime As String)
>> >        Dim g As System.Drawing.Graphics
>> >        g.DrawString(newTime, New System.Drawing.Font("Microsoft Sans
>> > Serif", 10, System.Drawing.FontStyle.Regular), New
>> > SolidBrush(SystemColors.ControlText), 200, 2)
>> >    End Sub
>> >
>> > But if I try this, I get a SystemNullReferenceExeption. Does sombody 
>> > know
>> > why?
>> >
>> > Thx,
>> > Cyberdot
>>
>>
>> 


Relevant Pages

  • Re: Drawing lines - another noob question
    ... graphics object just draws within the form you already have generated. ... Find great Windows Forms articles in Windows Forms Tips and Tricks ... I want to be able to draw ... lines in a picturebox based upon certain data points I have received. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Drawing a string
    ... picturebox on the same position where I want to draw the string, ... like the picture box is in front of the string I've drawn. ... to get the graphics handler for a picturebox? ... > draw with. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Inside PictureBox questions
    ... PictureBox is for displaying images. ... The statement that you can draw on it's ... #1 you ONLY draw on the Graphics object handed to you in the PaintEventArgs ... > A PictureBox has a Background Image, a Background color and an Image. ...
    (microsoft.public.dotnet.framework.drawing)
  • Re: Save lines drawn in the picturebox as an lmage
    ... you need to draw to a bitmap's Graphics object: ... Dim g As Graphics = Graphics.FromImage ... > of a barcode) in the picturebox paint event. ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Draw a line on top of a pictureBox
    ... If I add a pictureBox, the compiler takes care of managing the actual bitmap ... so how do I reference a picture for my new graphics object? ... If you want to draw on your bitmap, you can do this as follows: ... you can draw what you want with the Graphics object. ...
    (microsoft.public.pocketpc.developer)