|
hi, erm there are no error. currently i'm drawing it directly onto the form. i only draw it onto the form when i click a button.
//initially,set picturebox enable properties as false;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if(pictureBox.Enabled == true)
{
Drawpicture(e.Graphics);
}
}
private void Drawpicture(Graphics a)
{
Graphics myGraphics = CreateGraphics();
....
}
private void button2_Click(object sender, System.EventArgs e)
{
pictureBox.Enabled = true;
}
By doing this, i display my drawing onto the form when the button is click. However, i want to display it into the pictureBox when the button is click. How should i do that.
Chris
|
|
|
|
|
Maybe I'm reading this incorrectly but isn't this what you want:
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if(pictureBox.Enabled == true)
{
pictureBox.Image = CreateGraphics();
}
}
|
|
|
|
|
I would make a custom PictureBox by inheriting a new class from PictureBox and giving it an override to its OnPaint method.
In the constructor for your new PictureBox inheritor you make these calls:
this.SetStyle(ControlStyles.UserPaint, true);
this.SetStyle(ControlStyles.AllPaintingInWmPaint, true); this.SetStyle(ControlStyles.DoubleBuffer, true);
I understand these enable the control to draw itself in an efficient manner. Hope that helps. Please try to be more specific and plz is not a word.
vir·tu·al re·al·i·ty
n. Abbr. VR
A computer simulation of a real or imaginary universe in which Microsoft APIs are thoroughly documented and behave in an entirely logical manner.
|
|
|
|
|
hi, currently i'm drawing it directly onto the form. i only draw it onto the form when i click a button.
//initially,set picturebox enable properties as false;
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(e);
if(pictureBox.Enabled == true)
{
Drawpicture(e.Graphics);
}
}
private void Drawpicture(Graphics a)
{
Graphics myGraphics = CreateGraphics();
....
}
private void button2_Click(object sender, System.EventArgs e)
{
pictureBox.Enabled = true;
}
By doing this, i display my drawing onto the form when the button is click. However, i want to display it into the pictureBox when the button is click. How should i do that.
Chris
|
|
|
|
|
If you want to draw on the PictureBox , then you can't draw on the Form . The painting operation has to occur for the control on which you're actually painting.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
my problem is the following: I have a class called MyClass. A second class MyDerivedClass is derived from MyClass. A third class MyTwoTimesDerivedClass is derived from MyDerivedClass. Now I have some public variables and Methods in MyClass, which I want to use in MyDerivedClass. But I don't want them to be part of MyTwoTimesDerivedClass. How can I prevent them from being derived further?
Thanks,
Benjamin
|
|
|
|
|
That indicates there's a fundamental problem in your OO design that you may want to consider changing. Derivative child classes are supposed to inherit or override functionality from their parent classes. That's what polymorphism is all about (well, about the overriding, mostly).
You could defined the members as virtual in MyClass and override them in MyTwoTimesDerivedClass , only to throw a NotImplementedException or NotSupportedException . Furthermore, you can hide these from both the component designer and source code editor using the appropriate attributes like so:
[
Browsable(false),
EditorBrowsable(EditorBrowsableState.Never)
]
public override void BaseMethod()
{
throw new NotImplementedException();
} That will hide them, but you can't "undefine" an inheritted member.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
You mark a method in MyDerivedClass "sealed" which would mean MyTwoTimesDerivedClass cannot override it, but that doesnt hide it from them as stated in the post above.
public class MyClass
{
public virtual void DoSomething(){}
}
public class MyDerivedClass : MyClass
{
public override sealed DoSomething(){}
}
public class MyTwoTimesDerivedClass : MyDerivedClass
{
}
|
|
|
|
|
1. Post a reply to the parent post, not mine. You're replying to him. I know very well what the sealed keyword does.
2. That's not actually what he asked. The original post was about "un-inheritting" methods from a base class. Yes, sealed may be a good idea to use so derivative classes couldn't override and re-implement the methods, but - as I mentioned - the fundamental flaw is with his OO design. He shouldn't extend classes if he absolutely does not want to inherit their functionality. All you can do in these cases is hide members and either get/set/return the base class's member value or throw an exception. This is actually done in many places throughout the Windows Forms classes in the BCL, but only because the class members don't make sense in some cases (not to stop you from using them).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello,
I have a little problem. Maybe someone here can help me.
The problem is: My program (written in C# .NET) calls a COM-Server. This Server works a little bit and then he sent me the Results back in a callback-method. This method is open by the COM-Server in a new Thread. So far so god.
After I became this results I have to sent the next command to the server. But before I can sent a new command, I have to release the complete callback-method from the COM-Server. But I can’t close this method before sending the new command.
At the moment I open a new Tread in this callback-method. This new Thread sent the new command after the old Thread closed. But sometimes the old Thread closed not so fast and then it crashes.
Is there a any standard way to solve this Problem?
Can someone help me?
Sorry for my English
David
|
|
|
|
|
What's the threading model of the COM server?
If you're objective is to send the next command back to the server in the first thread (the thread on which your proxy was instantiated), then you need to invoke a method on that thread. If you're calling methods on your proxy from a Windows Forms control or form, you can use Control.Invoke . The Framework handles calling the method on the thread on which the control was created if you call it right. For example:
delegate void SendCommandHandler(string command);
void SendCommand(string command)
{
}
void Callback()
{
if (InvokeRequired)
{
SendCommandHandler d = new SendCommandHandler(SendCommand);
Invoke(d, new object[] {"DO SOMETHING"});
}
else SendCommand("DO SOMETHING");
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
At first: Tanks for this Information,
The COM-Server is a STA Server but I can use only one Apartment at the same time, because the Server needs very mutch Performance.
So the problem is not to start a new Thread. (The invoke command is very nice) At the moment I sent the next command in a other Tread too, but it starts like this:
SentCommand wrapper=new SentCommand(Thread.CurrentThread,myobject);<br />
ThreadStart ts=new ThreadStart(wrapper.SentNewCommand);<br />
Thread SecondThread = new Thread(ts);<br />
SecondThread.Start();
The real Problem is the speed of the second Thread. When I start the second Thread from the Callback-Tread both Thread exist at the same Time. So if the Second Thread is too fast and sent the new command before the Callback-tread is closed -> it crashes. So I think its not important if the Second-Thread is a new one or a existing GUI-Tread (Control).
I tried to synchronise this 2 Treads like this:
if (CallbackThread != null) <br />
{<br />
if (CallbackThread.IsAlive)<br />
{<br />
CallbackThread.Abort();<br />
}<br />
}
but it doesn’t work.
|
|
|
|
|
What you're doing isn't synchronizing thread access - you need locks for that. The C# lock statement does just that. Define a static object initialized to an instance of something. In your case, you could also synchronize against this since your .NET component is running in an apartment.
The lock uses a Monitor . There's also Mutex and various events you can signal. I suggest you read through the documentation for the namespace members in System.Threading . There's a lot of ways you can correctly synchronize thread access.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Can somebody please give me some sample code
to play wav files through a TAPI interphase.
Thanx...
|
|
|
|
|
It's been said many times before in this forum (just Search first!), and as recently as yesterday, the TAPI 3.0 wrapper is heavily rumored to have problems, so you'll have to use a custom written TAPI 2.0 wrapper. You can find such an example here[^] on GotDotNet.
RageInTheMachine9532
"...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
|
|
|
|
|
Hello,
I would like some help on the next problem I've encountered.
I want to know on my mainform if a child form was closed using the close-x of the window.
Microsoft says that you have the OnMdiChildActivate methode but this happens,
I quote "Occurs when a multiple document interface (MDI) child form is activated or closed within an MDI application."
Can anyone help?
|
|
|
|
|
Assuming the child has a reference to the mainform, then just give mainform a ChildClosed member, and put something like
parent.ChildClosed(this); in the close handler for the child form
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Sorry,
I'm just a beginner, so put something like... is a bit to non-specific for me.
Can you give a bit more details please.
Like what do you mean with a ChildClosed member?
|
|
|
|
|
"ChildClosed" was just a suggestion for a name - what I meant was in your MDI container class add a member function (call it whatever you like - ChildClosed seems to be a sensible name to me) that takes a parameter of whatever your child form type is
e.g.
public void ChildClosed( MyChildFormType ChildForm )
{
}
Now assuming your child window has some kind of parent property that's set when the child is first created, you can call the ChildClosed member from within the child's close window handler
--
Help me! I'm turning into a grapefruit!
Phoenix Paint - back from DPaint's ashes!
|
|
|
|
|
Sorry but I'm not quite where I want to be.
I will try to rephrase the problem. In my mainform I'vr got a menu for the 'windows'. You know the standard cascading en windowlist stuff.
I want to hide this menu just untill there are elements in the MdiList,
if(this.MdiChildren.Length > 0)
windowMenu.Visible = true;
Where do I put this check on the Mdichildren so I can be sure that when the Child is closed, but whatever method, the check is performed?
I've tried this:
void MainFormMdiChildActivate(object sender, System.EventArgs e)
{
CheckMdiList();
}
This is called when you 'open' or 'close' the child. The problem is that at that moment the child still exists, so it's still in the list.
Is this making things cleare of just the opposite?
Either way, I already want to thank anyone for the given help.
|
|
|
|
|
Jonckheere wrote:
Where do I put this check on the Mdichildren so I can be sure that when the Child is closed, but whatever method, the check is performed?
Why not create a timer that fires, say, every half a second, and do your updating from there? Apart from the Window menu, you can update your toolbar, status bar and so on.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
|
|
|
|
|
Hi all,
I want to know how to change a C# application to run in background from inside the program, i.e. the user can click a button in the GUI of the application, so that the application/or some of its process can run at background, so it won't compete resources with the other applications in foreground.
Thanks
Patrick
|
|
|
|
|
Hi!
Check out the usage of System.Threading.Thread - 'IsBackground' Property and use if it suits ur need.
Regs,
Manivannan.P
|
|
|
|
|
Hello .
Iam new to c#.
How a message to send to all clients in LAN network.
like "Net send" command
|
|
|
|
|
This has been covered in this forum many times. Whether or not you're new to programming or even just a particular language, basic research skills are a must in the field of development. Next time, please search first. You can search this site's articles using the search box at the top of every page, or click "Search comments" in every forum to search previous threads. You could also just google the entire web.
The simplest way is to just use "net send" using the Process class:
Process.Start("net", "send /domain Hello, world!"); The other way is to P/Invoke the native functions but requires you understand what P/Invoke is. If you want to go that route, I suggest you search for the previous threads about "net send" and you'll find links and examples, but the method above works just fine.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|