I am in the process of learning C# as I am most familiar with C++ so if there is a simple answer to this question please forgive me. Also thank you for taking the time to read this, I appreciate it!!! :)
I am currently in the process of creating a program similar to MS Paint. I would like to be able to draw text on a panel. I've found the .DrawString() which can apparently be used to do exactly this, though in all of the examples I've seen they have coordinates predefined and do not allow the user to choose where to place it. I want this to be similar to MS Paint by allowing the user to click and drag to make the size of the box the text shall appear in. I am not concerned about allowing them to move the text around once the rectangle is drawn with the text.
I was originally thinking to have them type their string into a textbox and then draw it onto a rectangle so they could size it appropriately to fit their string since the string should wrap inside of the rectangle. So I have two questions:
How can I have the text wrap around the rectangle and obviously cut
off anything that does not fit (again similar to MS Paint)?
By drawing a rectangle (if my idea is plausible of course) it will
leave a border around the text since it is making a rectangle. I do
not want this border, I only want the text. How can I achieve this?
Related
Imagine a panel with 4 PictureBox aligned in one line and then you decrease the size of the window and hence the panel size (it's anchored). Then, when there is no space for 4 PictureBox in one line, the last one goes down to the second line, becoming three PB in the superior line and the forth PB in the second.
If you continue decreasing the window size, the boxes will go down until remain a unique column of PictureBox.
The only idea that came mind was use "if" conditions... Is there an easier way to do that? I thought it could be made by some property of the panel or PB, but I'm wrong I suppose...
Summarizing: How to make the elements inside a panel be adjusted to fit in the panel when you change your size?!
Here it goes a image to illustrate the situation:
#Idle_Mind, Yes, Windows Forms Application. I've forgotten the FlowLayoutPanel, but I don't like it very much, if someone knows some way more easy, feel free to comment. For now, I will use the FLP. Thank you n_n
Just passing to mark the question as answered (on a comment in my question). I didn't use to know controls as FlowLayoutPanel or WrapPanel, etc. Thanks Idle_Mind.
I need the property called SelectionColor in the TextBox class, for a simple Syntax Highlighter - I can't use directly a RichTextBox - it causes too many problems, that's why I try to do this.
Is there any way to make that property available for a TextBox?
If it isn't possible, I'd try to write my own, but I need an idea on how to do it, basically how it works - is it based on drawing strings over the original text?
Thanks in advance.
Basically, using a TextBox for anything but plain text is a bad idea. First of all, you will eventually get a new feature to implement which is not present in TextBox and you will have to handle it manually. After some time you will implement a custom RichTextBox or something similar.
Second, it is relatively hard to even solve the problem you mentioned. Technically, you can override painting function (which you have to do if you want new functionality for TextBox). You can then let TextBox paint itself and paint the colored text above the image. But don't do it. You will get two (maybe more) problems:
Flicker of image. Once the original textbox has drawn itself, the image can be shown on screen (if you don't use double buffering).
Text alignment. It is hard to place colored text exactly above black text, plus you can run into problems with text rendering: you will need to clear area you're drawing in.
I am trying to figure out how to add a full shadow around a borderless form, using WinForms. I am looking at adding a shadow around all four sides of the form.
I have tried using the DropShadow class, although it only adds the shadow to the bottom and right side corners.
I have seen this question asked many times before in my searches but nothing I cam upon had an answer for all four sides.
I am using both C# and VB.net languages in my solution so any help regarding either language would be a big help.
You are going to have to manually draw this. I have done something similar before with a splash screen, I think. You need to decide the offset of the shadow from the client area of the form and either create a container (easier layout wise) to host its constituent controls or redefine its client rectangle programmatically if you need dynamic shadow size, and then draw your border. If memory serves, you will get the best results using alpha blending + lineargradientbrush to fade the shadow transparency out to the edges.
summarizing I have implemented a chart control as a simple Canvas with a Polyline on it. The next thing I need is to be able to zoom the chart.
I would like to know how would you that (just the idea, no details needed). What I would like to do is to create somehow a bigger Canvas and paint the line bigger and just show a part of the Canvas to the user, and the he drags the Chart it will move the Canvas. Something like in the following picture. Do you think this is possible?
Kael Rowan from Microsoft Research built a ZoomableCanvas class that may do exactly what you want. You can also see all the posts he wrote about it. You can even try a running XBAP example if your browser supports it.
We use the RenderTransform for this, create your zoom and pan matrix( or transform ) and apply that to your canvas. The nice thing is, that you can still have elements that can display behind or on top of the canvas with the identity transform or with another. For example for a grid or screen space elements like a minimap, which should always be visible. You might also want to look into this old question, which is somehow related.
my current free-time project, in order to dive into WPF MVVM, is a "digital" copy of an old puzzle I used to play a lot in my childhood. It basically is a simple puzzle where one has to fill a given space with different kind of pieces so the whole space is filled. But with the extra twist of being in hexagonal space.
Just to illustrate, this is what it currently looks like in WPF:
http://img190.imageshack.us/img190/2553/atomgridmolecule.png
So basically there is a number of predefined pieces(like the orange one above) which can be "plugged" into the given grid(the gray stuff above).
So the result might look something like this:
http://img30.imageshack.us/img30/2553/atomgridmolecule.png
I want the user(probably only me^^) to be able to drag and drop the pieces into the grid. I want the dragging to look natural meaning having the correct offset while dragging depending on where the user clicked the piece.
Both grid and molecule are the same control, a custom hexagonal panel control derived from the WPF Panel class.
The problem is on how to do the "plugging in" and especially the "unplugging".
I have two ideas on how I might tackle this:
Just color the cells in the grid and hiding the original piece
Pro:
Zero cost perfect alignment of the cells
Cons:
Recreating the piece at the right spot with the correct mouse offset if dragging out, seems impossibly? hard to do
Snapping the piece to the grid and show it on top
Pro:
Dragging out is a simple dragging operation, just as dragging in
Disadvantage:
Somehow have to align the piece with the underlying grid, some kind of snapping
So which approach should I take? Even more important how can I even implement this in WPF? Especially using a clean MVVM way.
Thanks so much for your help! Any input is highly appreciated!
EDIT:
Thanks Aran, I thought so too.
But how do I actually implement this now?
How can I actually get the coordinates?
All the orange circles are linked, so how can I "move" or better "plug" them in as one piece?
Im inclined to go with the second idea. a simple snapping would just be to test if the centre point of the circle you are dragging is within some tolerance factor of a circle on the grid and if so snap them.