Scrollable Controls and Areas in .NET with GDI+ - c#

I am having trouble understanding the proper way to create a scrollable area within a custom control using C#, .NET 3.5 and GDI+.
Is there any documentation from Microsoft about the correct way to go about doing so? Is there a decent primer anywhere on the web?
My concerns are mainly: if I create a large graphical canvas in memory, what are the specific details about how large the canvas can (and should be)? What are the performance considerations? How much of the scrollable area should I render in advance?
For example, if I were rendering a very large graphical plot from pre-existing data, should I just render the ENTIRE plot to graphic memory and then blit it into the "scrollable" area? Or, would that exhaust available graphic related memory and start writing into the paging file?
Clarification:
For example, your web-broser isn't "redrawing" the client area everytime you scroll by re-rendering all of the elements. Static elements of the page are rendered once to a large surface, and when you move the scroll bar, the starting offset of the pre-render is simply modified.
That is the sort of behavior I'm going for. I don't want to "draw the content that would be between the start and end values for my scroll range" on paint events.

If you are talking WinForms - derive your control from ScrollableControl. Define the Client Size and just paint the appropriate portion in OnPaint.
The control handles all scrolling details for you

Related

Artificially increasing size of .NET WebBrowser? (WinForms or WPF)

I am wondering if there is a way to artificially increase the size of a control (more specifically, a web browser) in .NET C#, or any language for that matter. By artificially increase, I mean, make every pixel take up the space of 4, effectively making the control 2 times larger.
I would like to make not only the webBrowser be twice as large, but all the content on it as well. Such that a 200x200 image on a website would appear to be 400x400, to the eye of the user.
I was able to achieve this effect by simply forcing a screen resolution change, which made the control appear bigger, but this is not the way I want to do it.
Does anyone know of a way to achieve this? Drawing to a canvas or picture box is not an option, as it would be too slow..
Thanks in advanced!

Drawing a lot of lines and other shapes in WinRT App

In my WinRT app I need to draw about 3000 objects on a canvas, where I can translate and zoom the view. Unfortunatley, after adding about 1500 lines to my canvas my Windows 8 App always crashes. What could be the best practice to achieve this?
One solution could be rendering everything on an image (how do I do this?). But then I loose comfort of easy access and editing of every element.
Also my scale and translate is very slow. But since I also need a big overview, it makes no sense to put only the objects of the visible area in the canvas, since on minimum zoom it's still everything and zoomed it's still very laggy cause of add and remove operations.
There are a couple of different things you should employ to have a smooth UX:
Use a Quadtree, whenever you add a shape to your canvas you also put it on your Quadtree. This will be helpful when you will zoom on a portion of the image: you will know what objects are in this portion of the image; you will render them again (against using a cached/pixellated version).
To overcome the potentially lengthy drawing process you could do the following:
display the portion of the cached image overview at the right scale
use a progress indicator to let know the user that the program is working render this portion
when the faint rendering is done, blit it on the screen
A concrete example: Google Maps does that.

Create an Object Editor in C# for WinForms

I need to find, or create an editor that will handle text and images as objects. For instance I have a 3 line string of text, to be able to move it around and position it within a canvas, also the ability to add an image, and possibly resize it within that canvas. and take the result, and save it, whether I get the the offsets and positions manually, of each of the objects (preferable) , or get the entire canvas as an image, to be able to save and print.
Rulers would be great... Im not trying to re-create Photoshop, but the idea is similar.
I will be doing this in a C# WinForms application, it does seem however that a WPF solution might be better suited, and I think I can have a WPF control within winforms...
Any direction or advice would be greatly appreciated.
Forget winforms. It doesn't support anything. Your best bet is to do it in WPF and if you need, you can integrate it into an existing winforms application via the ElementHost.
Please see my similar answers/samples about this:
https://stackoverflow.com/a/15580293/643085
https://stackoverflow.com/a/15469477/643085
https://stackoverflow.com/a/15821573/643085
Also, see this example with support for zoom, panning and resizing functionality:
https://stackoverflow.com/a/16947081/643085
They're all MVVM based and have some interesting features.
You can easily customize these samples and add ANY type of elements:
images,
geometries,
usable interactive UI elements with functionality (TextBoxes, ComboBoxes, whatever),
text,
videos,
FlowDocuments,
or whatever that's visible on screen)
by adding additional data items and their corresponding DataTemplates.

Developing a drawing utility in C#

I am trying to create a simple drawing utility as .net desktop application(i.e Windows Form using C#). What i am planing to develop is:
There should be a canvas area (This is the area where the actual drawing is performed).
The canvas should be zoomable (Zoom in and zoom out)
The canvas areas should have grid lines (the ideal size of grid is 100X100pixel, but it can be changed with zooming)
There is a single character written inside each cell (here by the term "cell" i am refering to the box that is formed by the intersection of grid lines)
Now until this step all the thing are automatic (i.e user don't have to do anything until now all is done by my application)
User is only allowed to draw rectangles in canvas area(my application will also need to keep the track of those rectangles in such a way that user is allowed to resize those rectangles later)
Since i am beginner to C# so i need only guidance. Till now i just look at System.Drawing library (only look at it don't go deep :P) but not sure should it cater all my requirements or not (but i guess it will cater my req) and if it will then from where do i start with and what resource do i need to study in order to create this application.

Creating an image containing text with drop shadow using WPF, but inside a ASP.NET web app

Ok, I have a rather strange request.
Due to the inconsistency in how different browsers support text with drop shadow, I was thinking that the text I need with drop shadow (some headers), I could create dynamically on the server side of my web app, and then pass the image to the browser instead of text directly.
I want to use WPF for this, since WPF has a lot of text manipulation built in, and it should be significantly easier to make text with drop shadow in WPF compared to GDI+.
So what I need to do is inside my Web App, create a WPF text element with the drop shadow effect, and save it inside an image (either to disk, or better yes pass it directly to the browser since I actually do not need to store the image since it will be specific for that request only).
I'm hoping for at least some pointers in the right direction :)
I just want to say, since this is unanswered and I don't use WPF that much, GDI+ would actually be pretty easy:
Draw text on image using the desired color of the shadow.
Do a box blur (or Gaussian).
(optional) Create another bitmap and do basically a watermark style draw (this would allow you to set opacity and thus soften the shadow, etc.)
Draw text again using color desired for the text
With that you would have yourself text with a drop shadow. There's about 10 different image processing libraries that make it rather simple (I will sadly do some self promotion and just say that Craig's Utility Library has a draw text function and box blur function in the Utilities.Media.Image.Image class, but there's tons of other packages you could use).

Categories