Results 1 to 6 of 6

Thread: Want to retain property of Autoredraw and clipcontrol.

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2017
    Posts
    45

    Want to retain property of Autoredraw and clipcontrol.

    Hi All,

    Kindly suggest me how to retain property like Clipcontrol and Autoredraw property for forms.

    After running my application, if i press Window+E button ,it start flickering. So i have make paint method in paint event and make doublebuffered property true, but yet it is flickering .

    After that i make one bitmap by using this code

    bitmap1 = new bitmap(Me.width,me.height,Me.creategraphics)
    graphic1= graphic.fromimage(bitmap)
    graphic1.drawimage(Image.jpg,0, 0, Me.width,Me.Height)
    Me.creategraphics.drawimage(bitmap1,0,0,Me.width,Me.height)
    Me.backgroundimage= bitmap1

    It start working, it is not flickering now but i drw some string in above that image in runtime through drawstring. That string is always frickering.

    My application has to run in multmonitor. So i have done same thing for multimonitor. I want to persist that string as well in form.

    I am converting code from vb 6.0 to vb.net, previously in vb 6.0 they simply call Form1.paintpicture(image,0,0,Me.Height,Me.width) and through print method they print string to form and they make autoredraw poperty and clipcontrol to true, but this property is not available in vb.net. How can i solve thid flickering issue.

    After pressing window+E, each time form_paint method gets fire and they call drawstring and drawimage . But through above procedure, flickering is stopped in image but string is yet flicker.
    Kindly suggest me.

  2. #2

    Thread Starter
    Member
    Join Date
    Jun 2017
    Posts
    45

    Re: Want to retain property of Autoredraw and clipcontrol.

    One more request, After pressing window+Tab button, i can able to cross my form application, but in vb6.0, that form is not gets close if we press cross button.

    I want to reatin that property as well. Kindly suggest me.

  3. #3

    Thread Starter
    Member
    Join Date
    Jun 2017
    Posts
    45

    Re: Want to retain property of Autoredraw and clipcontrol.

    I enable topmost button, so that no one able to open taskmgr to close my application my application will close through registry of window but after pressing Window+Tab button, we can able to cross my application through mouse. I want to disable this. This application is like sreensaver, if user can close through cross button then no use of it. It should kill through registry. Killing through registry is implemented but it is killed through cross button also.

  4. #4
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Want to retain property of Autoredraw and clipcontrol.

    You might want to rework your drawing code. There's only one case where you should be using CreateGraphics(), and it doesn't really have anything to do with drawing.

    If you handle the Paint event, you get a PaintEventArgs, and it has a Graphics object already made for you. That is the best, most efficient way to draw to the form.

    But if you're setting the BackgroundImage property, there's not a good reason to draw the image. The form will do that automatically for you. That could be part of the flicker, as well.

    You actually don't have to do much to get a Bitmap/Image from a file on disk. There's an Image.FromFile() method that does the trick. I'm not sure if it's faster, but why do work you don't have to? Alternatively, if it's always the same image, why not make the image a resource so you can set BackgroundImage in the designer and forget about it?

    Here's an example of the code I would write if I wanted to have a background image and draw text on top of it. I'm assuming the image is something the user chooses, so I put that code in a button click handler.
    Code:
    Private Sub Button1_Click(...) Handles ...
        Dim imagePath As String = txtImage.Text
        Dim newImage As Image = Image.FromFile(imagePath)
    
        ' It's tricky to deal with old images, we can't destroy them
        ' while they are in the PictureBox!
        Dim oldImage As Image = Me.BackgroundImage
        Me.BackgroundImage = newImage
        If oldImage IsNot Nothing Then
            oldImage.Dispose()
        End If
    End Sub
    
    ' Now the part that draws strings.
    Protected Overrides Sub OnPaint(ByVal e As PaintEventArgs)
        e.Graphics.DrawString("Here's some text", Me.Font, Brushes.White, New Point(10, 10))
    End Sub
    If that still flickers, I'm curious how you enabled double buffering. They added a property to Forms at some point to enable it, but before that there was a different way to enable it. Sometimes I feel like it works better if you do it both ways.

    I don't really understand the other requirement. You contradict yourself a lot:
    "...if user can close through cross button then no use of it
    ...but it is killed through cross button also.
    Even taking other things into account, you might be trying to do something that is against what Windows wants. You shouldn't try to evade Task Manager, and even if I knew a way to do so I wouldn't help another person do it.
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

  5. #5

    Thread Starter
    Member
    Join Date
    Jun 2017
    Posts
    45

    Re: Want to retain property of Autoredraw and clipcontrol.

    Ya fine but what about multiple monitor There are two form .
    1. form 1 --> in which i have written all logic and other is Muliform(which is blank).

    How i can differentiate which graphic object i need to take. There are 1 image which is fix on top of it, multiple small image will come so that it fills like all image is running. All image is taken from user at runtime from file. Several small image will place in in a centre of main image. So while flickering is start, main image is not flicker but some image which is already drawn on top of main image is went. How can i persist that thing.

    like

    form_load()
    {

    bitmap1 = new bitmap(Me.width,me.height,Me.creategraphics)
    graphic1= graphic.fromimage(bitmap)
    graphic1.drawimage(Image.jpg,0, 0, Me.width,Me.Height)
    Me.creategraphics.drawimage(bitmap1,0,0,Me.width,Me.height)

    'for mulilple screen

    collection(2) = new multiform
    bitmap2 = new bitmap(Me.width,me.height, collection(2).creategraphics)
    graphic2= graphic.fromimage(bitmap)
    graphic2.drawimage(Image.jpg,0, 0, Me.width,Me.Height)
    collection(2).creategraphics.drawimage(bitmap2,0,0,Me.width,Me.height)


    }

    timer_tick()
    {
    image1 = fromfile(image2.jpg)
    rect = new rectangle(10,20,120,130)
    Me.creategraphics.drawimage(image1 , rect, 5,5,540,450,Me.graphicunit.pixel)
    ' again for multimonitor doing same as previous
    drawstring(1) ' draw string on single monitor
    drawstring(2) 'draw string on multimonitor


    }

    drawstring()
    {
    me.creategraphics.drawstring() ' for single monitor
    collection(2).creategraphics.drawstring() ' for multmonitor
    }

    form_paint()
    {
    Me.creategraphics.drawimage(bitmap1,0,0,Me.width,Me.height)
    collection(2).creategraphics.drawimge(bitmap1,0,0,me.width,Me.height)
    }

  6. #6
    You don't want to know.
    Join Date
    Aug 2010
    Posts
    4,580

    Re: Want to retain property of Autoredraw and clipcontrol.

    If you have 2 forms, you have 2 Paint events. That's how you tell the difference.

    Don't have one form draw on another. It's not a good idea to make everything tangled up like that. The phrase used to describe it is "spaghetti code", because to figure out how one form works you end up having to follow a call chain through many places. It's not fun to maintain and not fun to debug!

    Have one form set a property on the other that causes it to draw.
    Code:
    Public Sub Form2
    
        Private _specialText As String
        Public Property SpecialText As String
            Get
                Return _specialText
            End Get
            Set(...)
                _specialText = value
                Invalidate()
            End Set
        End Property
        
        Overrides Sub OnPaint(...)
            e.Graphics.DrawString(SpecialText, Font, Brushes.Black, New Point(0, 0))
        End Sub
    End Sub
    
    Public Sub Form1
    
        Private _form2 As New Form2
    
        Overrides Sub OnShown(...)
            _form2 = New Form2()
            _form2.SpecialText = "I just got created!"
            _form2.Show()
        End Sub
    
        Sub Button1_Click(...) Handles ...
            _form2.SpecialText = "Hey this changed!"
        End Sub
    End Sub
    This answer is wrong. You should be using TableAdapter and Dictionaries instead.

Tags for this Thread

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