|
Hello everyone,
I have made a basic windows form that I can draw on. The problem is that
when I resize the form the drawing disappears or gets clipped accordingly
how can I draw on the form and maintain the drawing even if I resize the form?
clear steps in a tutorial manner would be highly appreciated
thanks everybody for being there
|
|
|
|
|
You need to redraw it each time the window is damaged. You do this by overriding the OnPaint() method.
|
|
|
|
|
well sounds good but the code for drawing on the form is kept inside the MouseMove Event whenever it is fired it checks to see whether the left mouse button is pressed and then it draws according to the mouse movement.
The drawing is using the graphics object, let's say of a form or a panel on the form. How will the OnPaint method recognize the drawing?
I mean I get your point and it seems that it will work but can you explain a bit more?
|
|
|
|
|
You have to track all the drawing you do then when OnPaint fires recreate the drawing - if the form has changed size you can then rescale the drawing.
|
|
|
|
|
You really need an internal representation of your drawing.
You should build it up with mouse and/or keyboard events
and paint it in the OnPaint handler.
You then can also add file open and file save operations.
OnPaint is called automatically whenever there is a good reason to repaint the form or panel,
such as:
- form/panel became visible again (an overlapping form has been moved or closed)
- form gets resized (including form maximize, restore from minimize, restore from maximize)
- probably many more
- or you explicitly causing a repaint by calling Invalidate(), e.g. after you loaded a new file.
Luc Pattyn
|
|
|
|
|
Call Invalidate and pass it the region to be redrawn whenever you cause an event that needs to be drawn.
File Not Found
|
|
|
|
|
How in C# when I try to write over a file which another user has open do I find out their username so I can show it in a MessageBox?
TIA.
|
|
|
|
|
You have 2 people editing a file at the same time?
|
|
|
|
|
No, the application creates a PDF file - occasionally somebody might want to recreate the PDF file and even more occasionally somebody might already have the PDF file open - the chances of it happening are slim but if it does happen I would like to be able to display the username of the user who has the file open.
|
|
|
|
|
Why not just have a policy where users save the PDF to their local machine before opening? If they are viewing it via the web, send it via a stream, instead of the actual file.
|
|
|
|
|
What is the simpliest way to make a direct system call in managed C# (i.e. equivalent to system() function in C)?
I'm unable to find it on the internet..
|
|
|
|
|
If you'd like to call a function in the external library, you should look at DllImportAttribute and P/Invoke mechanism in .NET.
Wizard_01
|
|
|
|
|
No, I'd like to execute a shell command, for example 'chkdsk' or 'rm' or 'dir' (whatever). In the old ANSI C this was done by calling system(string) function from stdlib. I can't find a corresponding solution in .NET. If I have to, I will use P/Invoke to call system(...), but I don't know what library I have to import either (I don't think it is stdlib.dll..?).
|
|
|
|
|
I believe you want the System.Diagnostics.Process class.
--
Rules of thumb should not be taken for the whole hand.
|
|
|
|
|
Have a look at the Process class.
For simple commands a simple Process.Start(string) will do.
Luc Pattyn
|
|
|
|
|
Thanks a lot folks!
That was exactly what I was looking for.
|
|
|
|
|
Hi,
I have a user control in a window form. In user control i have a button.
On click over this button i want to change the window form label text.
How i can do it ?
I am new to c#. please help
|
|
|
|
|
delegates and events .
It's too difficult to explain in short text, but you can look up examples on google or MSDN.
V.
I found a living worth working for, but haven't found work worth living for.
|
|
|
|
|
I think the simplest way is:
1- add a usercontrol to your project
2- add a button, named in Button1 to your usercontrol, set Button1 "Modifiers" property to Public.
3- build your project.
4- after adding your user control, named in UserControl1 to your form, add this lines of code:
-------------------
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
AddHandler UserControl1.Button1.Click, AddressOf Button_Click
End Sub
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'do your task here
End Sub
-------------------
5- what you wanted is done
|
|
|
|
|
Unknown C# dialect.
Luc Pattyn
|
|
|
|
|
add these line of code to your form:
private void Button_Click(object sender, System.EventArgs e)
{
// do your task here
}
then in your form load event add:
UserControl1.Button1.Click += new System.EventHandler(this.Button_Click);
|
|
|
|
|
Sure.
I think I understood the first time.
My remark was it did not really look like C#, the subject of this message board.
Luc Pattyn
|
|
|
|
|
Hello,
Here some code for the suggestions from "V".
UserControl code:
public event EventHandler ButtonClickChanged;
protected virtual void OnButtonClickChanged(System.EventArgs e)
{
if (ButtonClickChanged != null)
{
ButtonClickChanged(this, e);
}
}
private void button1_Click(object sender, System.EventArgs e)
{
OnButtonClickChanged(System.EventArgs.Empty);
}
Forms code:
public Form1()
{
InitializeComponent();
userControl11.ButtonClickChanged+=new EventHandler(userControl11_ButtonClickChanged);
}
private void userControl11_ButtonClickChanged(object sender, EventArgs e)
{
}
Hope that helps!
All the best,
Martin
|
|
|
|
|
I just tried to generate some XML documentation for my project. The output is great as far as it goes but it's not very readable. Is there a tool like JavaDoc or doxygen available for .NET?
I tried to look into nDoc but the last reference to anything on their site was from 2004.
TIA
Russell
|
|
|
|
|
The NDoc project has stopped further development. The last official version supports .NET 1.1 only, but there are unofficial hacks that support .NET 2 roughly.
MS has Sandcastle in beta.
Sandcastle[^]
I don't know when it's due for release. Apart from that there are one or two commercial tools around. But I assume you are after free or open source?
|
|
|
|