Results 1 to 6 of 6

Thread: [RESOLVED] [2008] Main Form Shown Event and Draw in a textbox

  1. #1

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Resolved [RESOLVED] [2008] Main Form Shown Event and Draw in a textbox

    Hi!!

    I have several textboxes on my only form in my project. And inside the Shown event of my form I have a piece of code that Draws numbers into each every textbox using this (only part of the code is here):
    Code:
            If NumerosPossiveis.Contains("1") Then g.DrawString("1", Me.Font, New SolidBrush(Me.ForeColor), 3, 1)
            If NumerosPossiveis.Contains("2") Then g.DrawString("2", Me.Font, New SolidBrush(Me.ForeColor), 13, 1)
            If NumerosPossiveis.Contains("3") Then g.DrawString("3", Me.Font, New SolidBrush(Me.ForeColor), 23, 1)
            If NumerosPossiveis.Contains("4") Then g.DrawString("4", Me.Font, New SolidBrush(Me.ForeColor), 3, 13)
            If NumerosPossiveis.Contains("5") Then g.DrawString("5", Me.Font, New SolidBrush(Me.ForeColor), 13, 13)
            If NumerosPossiveis.Contains("6") Then g.DrawString("6", Me.Font, New SolidBrush(Me.ForeColor), 23, 13)
            If NumerosPossiveis.Contains("7") Then g.DrawString("7", Me.Font, New SolidBrush(Me.ForeColor), 3, 25)
            If NumerosPossiveis.Contains("8") Then g.DrawString("8", Me.Font, New SolidBrush(Me.ForeColor), 13, 25)
            If NumerosPossiveis.Contains("9") Then g.DrawString("9", Me.Font, New SolidBrush(Me.ForeColor), 23, 25)
    So when I run the program I should see all the drawn strings, instead I get this (See attachment)
    Its like he draw the strings correctly but then something draw over the strings.
    Why does this happen?
    Attached Images Attached Images  
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  2. #2
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Main Form Shown Event and Draw in a textbox

    1. All drawings need to be done in the Paint event of the control.
    2. If you want to draw on a particular control, you need to use the graphics object of that control.
    So now the question is, what event are you doing the drawing and what graphics object are you using? I hope you're drawing in the Shown event of the form
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  3. #3
    PowerPoster JuggaloBrotha's Avatar
    Join Date
    Sep 2005
    Location
    Lansing, MI; USA
    Posts
    4,286

    Re: [2008] Main Form Shown Event and Draw in a textbox

    Quote Originally Posted by stanav
    1. All drawings need to be done in the Paint event of the control.
    2. If you want to draw on a particular control, you need to use the graphics object of that control.
    So now the question is, what event are you doing the drawing and what graphics object are you using? I hope you're drawing in the Shown event of the form
    I hope he's not drawing in the form's shown event, I'd hope it's in the textbox's overridden on paint event
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

    CodeBank: All ThreadsColors ComboBoxFading & Gradient FormMoveItemListBox/MoveItemListViewMultilineListBoxMenuButtonToolStripCheckBoxStart with Windows

  4. #4

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2008] Main Form Shown Event and Draw in a textbox

    I'm using the graphics object of the textbox I'm currently drawing in.
    I hope he's not drawing in the form's shown event, I'd hope it's in the textbox's overridden on paint event
    Actually I'm drawing inthe form's shown event, because if I draw in the textbox's overridden on paint event I have to create a class that inherits form Textbox to do that, and I simply dont want to, unless there is no other option.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

  5. #5
    PowerPoster stanav's Avatar
    Join Date
    Jul 2006
    Location
    Providence, RI - USA
    Posts
    9,290

    Re: [2008] Main Form Shown Event and Draw in a textbox

    No, you don't have to create any class that inherits the TextBox class. You can just handle your TextBox.Paint event and doing the drawing there instead of doing it in the Form.Shown event as you're doing now.
    Let us have faith that right makes might, and in that faith, let us, to the end, dare to do our duty as we understand it.
    - Abraham Lincoln -

  6. #6

    Thread Starter
    Fanatic Member Lasering's Avatar
    Join Date
    May 2006
    Location
    Lisboa
    Posts
    559

    Re: [2008] Main Form Shown Event and Draw in a textbox

    Well, didnt work
    Code:
        Private Sub A2_Paint(ByVal sender As Object, ByVal e As PaintEventArgs) Handles A2.Paint
            Dim NumerosPossiveis As String = A2.Tag.ToString
            If NumerosPossiveis = Nothing Then Exit Sub
            Dim g As Drawing.Graphics = A2.CreateGraphics
            If NumerosPossiveis.Contains("1") Then g.DrawString("1", Me.Font, New SolidBrush(Me.ForeColor), 3, 1)
            If NumerosPossiveis.Contains("2") Then g.DrawString("2", Me.Font, New SolidBrush(Me.ForeColor), 13, 1)
            If NumerosPossiveis.Contains("3") Then g.DrawString("3", Me.Font, New SolidBrush(Me.ForeColor), 23, 1)
            If NumerosPossiveis.Contains("4") Then g.DrawString("4", Me.Font, New SolidBrush(Me.ForeColor), 3, 13)
            If NumerosPossiveis.Contains("5") Then g.DrawString("5", Me.Font, New SolidBrush(Me.ForeColor), 13, 13)
            If NumerosPossiveis.Contains("6") Then g.DrawString("6", Me.Font, New SolidBrush(Me.ForeColor), 23, 13)
            If NumerosPossiveis.Contains("7") Then g.DrawString("7", Me.Font, New SolidBrush(Me.ForeColor), 3, 25)
            If NumerosPossiveis.Contains("8") Then g.DrawString("8", Me.Font, New SolidBrush(Me.ForeColor), 13, 25)
            If NumerosPossiveis.Contains("9") Then g.DrawString("9", Me.Font, New SolidBrush(Me.ForeColor), 23, 25)
        End Sub
    What I did wrong?
    Last edited by Lasering; Sep 5th, 2008 at 04:09 PM.
    Controls: XPCC|Quantum
    Windows API'sLINQ to XML SamplesRegex Tutorial

    Albert Einstein:
    "Imagination is more important than knowledge."
    "Everything should be made as simple as possible, but not simpler."
    "Great spirits have often encountered violent opposition from weak minds."

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width