Hack Forums
[.NET] Scroll drawn GDI in custom control - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [.NET] Scroll drawn GDI in custom control (/showthread.php?tid=5592464)



Scroll drawn GDI in custom control - VmX5 - Apr 4, 2017

Hey guys, I need some help :(

So I have a Custom Control :

PHP Code

<?php 
Public Class RDrawing
    Inherits Control

End 
Class 

And I draw a very large object (It's not really this large)

PHP Code

<?php 
Public Class RDrawing
    Inherits Control

    
Protected Overrides Sub OnPaint(e As PaintEventArgs)
        
MyBase.OnPaint(e)
        
e.Graphics.FillRectangle(Brushes.Red, 10, 10, 1000, 1000)
    
End Sub
End 
Class 

How could I get a scroll bar in order to scroll though the drawn graphics?
Note: The Control will be set at a specified size, ex: (100, 100) <--- Not big enough to see all the drawn graphics, In my case I might need drawn text so I can't resize the drawn graphics.

Thanks ~VmX5.


* - hfTP54 - Apr 4, 2017

Either add the v/h scrollbar control as a child control or emulate one yourself with hit-testing.
Draw everything on a bitmap.
Then, clip it to a rectangle which corresponds to your scroll bars and control width ie. the area which you want to show.
FUrther, clip the graphics of your control to the ClientRectangle of the control to avoid unnecessary drawing.
Then draw that bitmap at a location (-x,-y) where x and y are values of the scrollbars. Do this everytime the user scrolls.


* - VmX5 - Apr 4, 2017

(Apr 4, 2017 09:27 PM)hfTP54 Wrote:  Either add the v/h scrollbar control as a child control or emulate one yourself with hit-testing.
Draw everything on a bitmap.
Then, clip it to a rectangle which corresponds to your scroll bars and control width ie. the area which you want to show.
FUrther, clip the graphics of your control to the ClientRectangle of the control to avoid unnecessary drawing.
Then draw that bitmap at a location (-x,-y) where x and y are values of the scrollbars. Do this everytime the user scrolls.

Thanks for the reply, I'll try it out and post back with results soon (Tmrw probs)


* - Visual Freedom - Apr 5, 2017

I often add a dynamic Y value for my controls and then write a custom scrollbar for this.


* - Zilog80 - Apr 5, 2017

Put a panel control with AutoScroll = true; as UserControl container.

Example: https://hackforums.net/showthread.php?tid=5458100