none
ControlPaint.DrawReversibleLine Method (Point, Point, Color) RRS feed

  • Question

  • Hi

    Tried a whole bunch of examples,and NONE do as expected. One example,supposedly the method explanation, by MS themselves, at EXAMPLE, fails. All the examples I have tried draw to the DeskTop with 0,0 as origin and all my attempts to apply the method to a Control (Panel in this case) using PointToClent etc just don't do as expected. The example at the link above, is supposed to draw a crossed lines on a Button, but it just still uses the DeskTop at 0,0 as the origin.

    Has anyone used this method and got the expected results?

    BTW: I do not actually have a project that I need this for,more an anomaly I am trying to get to grips with.


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, July 10, 2017 7:04 PM
    Monday, July 10, 2017 7:03 PM

Answers

  • Yes I copied the link.

    Your screen must be high res? Everything looks big? What is it? What is the dpi setting in control panel? is that it? See how the X you get is like half way like you need to multiply by 2.

    PS is that a full screen shot? Is it a tablet or something?

    PS2: check the coords for the form you get by form.left and the coords you are drawing X with, do they make sense?

    I guess its not a full screen?

    • Edited by tommytwotrain Monday, July 10, 2017 8:33 PM
    • Marked as answer by leshay Monday, July 10, 2017 9:05 PM
    Monday, July 10, 2017 8:24 PM

All replies

  • The MS example in the link seems to be working? See the X on button3 when the mouse is over the button?

    Do you have anything else going on that could be interfearing?

    PS What version windows do you have? I am win 7.

    Monday, July 10, 2017 7:11 PM
  • Hi

    I am on Windows 10 - but should that matter?

    When I tried the example, it was drawing the crossed lines on the DeskTop. Trying to get the correct behavior always failed with my attempts.

    I am not aware of anything else that could be interfering at all.

    BTW: it seems as though the code that Microsoft put in that example was not a tested version -there was a mistype in one line referencing the wrong button.


    Regards Les, Livingston, Scotland



    • Edited by leshay Monday, July 10, 2017 7:30 PM
    Monday, July 10, 2017 7:24 PM
  • Hi

    I am on Windows 10 - but should that matter?

    When I tried the example, it was drawing the crossed lines on the DeskTop. Trying to get the correct behavior always failed with my attempts.

    I am not aware of anything else that could be interfering at all.

    BTW: it seems as though the code that Microsoft put in that example was not a tested version -there was a mistype in one line referencing the wrong button.


    Regards Les, Livingston, Scotland



    I don't know. Works on my win10 sys too?

    So you run this and what happens? Can you get a screen capture?

    Public Class Form3
    
        ' When the mouse hovers over Button3, two reversible lines are drawn
        ' using the corner coordinates of Button3, which are first 
        ' converted to screen coordinates.
        Private Sub Button3_MouseHover(ByVal sender As Object,
        ByVal e As System.EventArgs) Handles Button3.MouseHover
    
            ControlPaint.DrawReversibleLine(Button3.PointToScreen(New Point(0, 0)),
        Button3.PointToScreen(New Point(Button3.ClientRectangle.Right,
            Button3.ClientRectangle.Bottom)), SystemColors.Control)
            ControlPaint.DrawReversibleLine(Button3.PointToScreen(
            New Point(Button3.ClientRectangle.Right, Button3.ClientRectangle.Top)),
           Button3.PointToScreen(New Point _
                (Button1.ClientRectangle.Left, Button3.ClientRectangle.Bottom)),
                SystemColors.Control)
        End Sub
    
        ' When the mouse moves from Button3, the reversible lines are 
        ' erased by using the same coordinates as are used in the
        ' Button3_MouseHover method.
        Private Sub Button3_MouseLeave(ByVal sender As Object,
        ByVal e As System.EventArgs) Handles Button3.MouseLeave
    
            ControlPaint.DrawReversibleLine(Button3.PointToScreen(New Point(0, 0)),
        Button3.PointToScreen(New Point(Button3.ClientRectangle.Right,
            Button3.ClientRectangle.Bottom)), SystemColors.Control)
            ControlPaint.DrawReversibleLine(Button3.PointToScreen(
            New Point(Button3.ClientRectangle.Right, Button3.ClientRectangle.Top)),
           Button3.PointToScreen(New Point(Button3.ClientRectangle.Left,
           Button3.ClientRectangle.Bottom)), SystemColors.Control)
        End Sub
    
    End Class

    Monday, July 10, 2017 7:47 PM
  • BTW: it seems as though the code that Microsoft put in that example was not a tested version -there was a mistype in one line referencing the wrong button.




    Oh, there you go I bet. I have 3 buttons on the form. Button1, 2 and 3. So make them and don't change it.

    PS Huh, yeah, I am not sure what is going on there but it works with 3 buttons as in my image.

    Button3.PointToScreen(New Point _
                (Button1.ClientRectangle.Left, Button3.ClientRectangle.Bottom)),
                SystemColors.Control)

    PS 2: Well that button clientrect.left is always zero so it matters not. Change to button3 I still get the X. 

    So I still cant duplicate the problem you describe. Can you?



    Monday, July 10, 2017 7:51 PM
  • Hi

    Without checking, the code you posted looks the same as the MS example.

    Here is a Screen Shot.


    Regards Les, Livingston, Scotland

    Monday, July 10, 2017 8:07 PM
  • Yes I copied the link.

    Your screen must be high res? Everything looks big? What is it? What is the dpi setting in control panel? is that it? See how the X you get is like half way like you need to multiply by 2.

    PS is that a full screen shot? Is it a tablet or something?

    PS2: check the coords for the form you get by form.left and the coords you are drawing X with, do they make sense?

    I guess its not a full screen?

    • Edited by tommytwotrain Monday, July 10, 2017 8:33 PM
    • Marked as answer by leshay Monday, July 10, 2017 9:05 PM
    Monday, July 10, 2017 8:24 PM
  • Hi

    Yes, I have:

    Surface Pro 5 (2 in 1 Tablet)
    2736 x 1824    ((recommended)
    Scaled to 225% (recommended 200%)

    That was a full screen shot.

    It could/might be the scaling that has thrown things awry.

    PS: I need the scaling as without it, everything is beyond my old eye sight.


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, July 10, 2017 8:33 PM
    Monday, July 10, 2017 8:31 PM
  • Hi

    Yes, the scaling was the culprit. I tested at 100% and it worked perfectly.

    I may try and do some scaling to the points to see if I can make it work at different system scales.

    Thanks Tom


    Regards Les, Livingston, Scotland

    Monday, July 10, 2017 9:04 PM
  • Hi

    Yes, I have:

    Surface Pro 5 (2 in 1 Tablet)
    2736 x 1824    ((recommended)
    Scaled to 225% (recommended 200%)

    That was a full screen shot.

    It could/might be the scaling that has thrown things awry.

    PS: I need the scaling as without it, everything is beyond my old eye sight.


    Regards Les, Livingston, Scotland


    Try this. This works for me. You may have to change dpiRatio to 96/g.dpix ? ie my dpi is 96 so its not doing anything to me.

    edit:

    Public Class Form3
    
        Private pt1, pt2 As Point
        Private dpiRatio As Double
    
    
        Private Sub Form3_Load(sender As Object, e As EventArgs) Handles Me.Load
            Using g As Graphics = Me.CreateGraphics
                dpiRatio = g.DpiX / 96
            End Using
        End Sub
    
    
        Private Sub Button3_MouseHover(ByVal sender As Object,
        ByVal e As System.EventArgs) Handles Button3.MouseHover
    
            DrawLine()
    
        End Sub
    
        Private Sub Button3_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.MouseLeave
    
            DrawLine()
    
        End Sub
    
    
        Private Sub DrawLine()
            pt1 = Button3.PointToScreen(New Point(0, 0))
            pt1 = New Point(CInt(dpiRatio * pt1.X), CInt(dpiRatio * pt1.Y))
    
    
            pt2 = Button3.PointToScreen(New Point(Button3.ClientRectangle.Right, Button3.ClientRectangle.Bottom))
            pt2 = New Point(CInt(dpiRatio * pt2.X), CInt(dpiRatio * pt2.Y))
    
            ControlPaint.DrawReversibleLine(pt1, pt2, SystemColors.Control)
    
            pt1 = Button3.PointToScreen(New Point(Button3.ClientRectangle.Right, Button3.ClientRectangle.Top))
            pt1 = New Point(CInt(dpiRatio * pt1.X), CInt(dpiRatio * pt1.Y))
    
            pt2 = Button3.PointToScreen(New Point(Button3.ClientRectangle.Left, Button3.ClientRectangle.Bottom))
            pt2 = New Point(CInt(dpiRatio * pt2.X), CInt(dpiRatio * pt2.Y))
    
            ControlPaint.DrawReversibleLine(pt1, pt2, SystemColors.Control)
    
    
        End Sub
    
    End Class

    You get the idea. Use the dpi ratio.



    Monday, July 10, 2017 9:06 PM
  • Hi

    Yes, the scaling was the culprit. I tested at 100% and it worked perfectly.

    I may try and do some scaling to the points to see if I can make it work at different system scales.

    Thanks Tom


    Regards Les, Livingston, Scotland


    You are welcome. See the last example using the g.dpix
    Monday, July 10, 2017 9:15 PM
  • Hi

    Just noticed it. I had something very similar, except, I used a ratio equsl to current scaling / 100 and that brought everything into line.

    I may, when I have the inclination, look for a .NET way of finding the current scaling - I just used a readout from Display Settings to test.

    BTW: you remarked that things looked very large on my screen shot. Just to let you know, those buttons were specifically enlarged to do the testing - normal buttons are much more petite normally :)


    Regards Les, Livingston, Scotland


    • Edited by leshay Monday, July 10, 2017 10:20 PM
    Monday, July 10, 2017 10:17 PM
  • Hi

    Just noticed it. I had something very similar, except, I used a ratio equsl to current scaling / 100 and that brought everything into line.

    I may, when I have the inclination, look for a .NET way of finding the current scaling - I just used a readout from Display Settings to test.

    BTW: you remarked that things looked very large on my screen shot. Just to let you know, those buttons were specifically enlarged to do the testing - normal buttons are much more petite normally :)


    Regards Les, Livingston, Scotland


    Yes there are some other ways and funny system things and this is where win10 can be different, some of the screen size things dont work the same with certain versions. Razerz has worked it out and there are some threads on it for getting the screen size with his latest but I cant find one.

    Things can also be different for the device you draw upon so thats why we may need to get the dpi of the drawing surface ie the .graphics, not just the screen setting. For example printing the dpi might be 1200 dpi etc. Primary and secondary monitors etc. It also depends on what you are drawing. Fonts can behave different sizes in some controls. And 125% scales certain things differently than 150%. Then there are some auto settings you can use to configure your app for dpi aware. On and on...

    Look at the images in the last example here etc.

    https://social.msdn.microsoft.com/Forums/vstudio/en-US/43e698ec-a57f-4cc8-aa25-1ea0fafda057/screen-size?forum=vbgeneral


    PS

    https://msdn.microsoft.com/library/windows/desktop/dn469266.aspx

    Monday, July 10, 2017 11:24 PM
  • Hi

    Well, that opened a whole new can of worms. I spent quite a while looking through the information from the links you posted.

    I can see that I could probably spend quite a while more to get to grips with all of that.

    In the meantime, I have found a sort of work round for one of my projects which does a better job than I had.

    For the project .exe file,  setting the Properties -> Compatibility -> Override high DPI scaling behaviour performed by :

    to Application allows my application to scale to any of the Scale set in the Display Settings. My application lets the User resize the form, and some code from IronRazer is used to autoscale the controls on the form - and it all works perfectly with the above Setting change.

    A bit of a shortcut, but in this particular case,does what is needed.


    Regards Les, Livingston, Scotland

    Tuesday, July 11, 2017 3:17 PM
  • Hi

    Well, that opened a whole new can of worms. I spent quite a while looking through the information from the links you posted.

    I can see that I could probably spend quite a while more to get to grips with all of that.

    In the meantime, I have found a sort of work round for one of my projects which does a better job than I had.

    For the project .exe file,  setting the Properties -> Compatibility -> Override high DPI scaling behaviour performed by :

    to Application allows my application to scale to any of the Scale set in the Display Settings. My application lets the User resize the form, and some code from IronRazer is used to autoscale the controls on the form - and it all works perfectly with the above Setting change.

    A bit of a shortcut, but in this particular case,does what is needed.


    Regards Les, Livingston, Scotland

    Les,

    Yup. Just depends on the application, which way you need to/easiest way to deal with it. And the monitor/device OS version comes to play sometimes as well with some of the auto things.

    The apps that I have made recently I have basically done away with controls and just draw the entire form myself. So as long as I stay with the local view form coordinates it is fine. Basically Razerz resize method but I draw my controls too which I now have sub classes for etc.

    However these are highly graphic applications ie drawing program, tank game, etc where the app benefits from addtional high speed drawing things.

    If the app was just controls with mostly text display then I would try the auto route. Perhaps with the dpi aware you put in the app.config?? or something. But I have never tested it and dont know how it behaves exactly but it seems to make OPs happy when they ask how to size their controls

    PS and back to the orginal question, drawing on controls can be done in the paint event. This drawreversable line stuff is really drawing on the screen, not the app, so there is really no need for it in a normal vb.net application.
    Tuesday, July 11, 2017 4:52 PM
  • PS and back to the orginal question, drawing on controls can be done in the paint event. This drawreversable line stuff is really drawing on the screen, not the app, so there is really no need for it in a normal vb.net application.

    Hi

    Yes, the drawreversable line stuff does interact with the screen itself. Being what looks like a useful thing, I wonder why its not included in form drawing? It would be handy from time to time.  Especially if you needed to draw over other elements of differing colors.


    Regards Les, Livingston, Scotland

    Tuesday, July 11, 2017 5:31 PM
  • Yes, the drawreversable line stuff does interact with the screen itself. Being what looks like a useful thing, I wonder why its not included in form drawing? It would be handy from time to time.  Especially if you needed to draw over other elements of differing colors.


    Regards Les, Livingston, Scotland


    Does drawreversableline do color? Or just inverse the color below based on the color you give. Also there is no drawreversable fill and etc so limited.

    I don't know what you have in mind. But, you don't need it for "form drawing" do you?

    Maybe there are useful things. I always found it goofy. And always did not use it in the end. Because I could always do it another way. But its been a while since I tried to use it. So not sayin don't.

    One thing about drawreversibleline, its not really OOP. Or whatever its called. You are not SUPPOSED to draw on and between windows (controls), or other applications, in Windows. Thats what the OS is for. Thats all I am going to say about it for various reasons. :)

    Tuesday, July 11, 2017 6:09 PM