|
Does anyone know if there's a Windows.Forms Control aviable I can use to create graphs (like SCPL), which has the possibility to set the axes in the center (not just Y-axis all-left and X-axis on the bottom)? I need to use it to draw math functions (very simple ones, form y=ax+b), but all controls I can find put the Y-axis on the left and the X one on the bottom :S. Being able to display points on integer positions (like (1,1),(1,2),(2,3),(-1,-5),(-1,6) and so on) would be a plus.
Thanks, Ikke
|
|
|
|
|
Well
int axisX = this.Width/2;
int axisY = this.Height/2;
a line with x and y
MoveTo(x+axisX, y+axisY);
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Mmm, you mean this little piece of code to write my own control? I can figure this out myself (really true LOL), but I doint know GDI+ (and Im too lazy LOL)
|
|
|
|
|
GDI is easier than kindergarten. DirectX and 3D is another story altoghter
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I have a new version of an assembly which is refereneced by my client application. I configured "Binding Policy" with ".NET Framework Configuration" tool - but the client is still referencing the old assembly.
I then tried to get around this temporary by configuring a Publisher Policy Assembly and gacutil -i the policy to GAC. No crash, but again, the client is referencing the same old package. I am sure I checked the "Enable Publisher Policy" checkbox before I install the policy assembly to GAC...
Can anyone tell me what are the common screw-ups for in assembly redirection? Thanks.
norm
|
|
|
|
|
Hi!
Can anybody imagine why a thread doesn't start when I execute the program within the VisualStudio .NET 2003 environment.
When I execute this exe in the command-shell everything works fine. (even with mono and linux).
This only happens with a certain project.
Any ideas ?
THANKS !!!!!!
|
|
|
|
|
Please post some code.. It'll be easier for us to help you.
|
|
|
|
|
Hi All,
I've never done any multi-threaded programming before and I'm having trouble getting some code to work as I want it to. Here's the situation: I have a POP3 client that I wrote (in a dll) and in the program that I'm using it from I want the user to click "Connect" (a button) to connect to the server. When they click connect it changes it's text to "Disconnect" and if they click it in that state it should disconnect from the server (even if it's in mid connection). I really have no idea how I should be going about this so any help would be greatly appreciated.
Thanks in advance
- monrobot13
|
|
|
|
|
If you can, keep have a variable that indicates whether or not to stop the operation, and keep checking that variable in the worker thread. But this is obviously not always possible. The other way to do it is to call Thread.Abort() on the worker thread. When you call Thread.Abort, the thread will get a ThreadAbortException. Handle the exception, and clean up any resources and close any connections before exiting.
try
{
}catch(Exception e)
{
}
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Should variables I need to use in a thread be static? I ask because this is what I'm trying to do:
Thread myThread = new Thread (new ThreadStart (ThreadFunc));
if (button1.Text == "Connect")
{
myThread.Start ();
button1.Text = "Disconnect";
}
else
{
popClient.DestroyConnection ();
button1.Text = "Connect";
myThread.Abort ();
myThread.Join ();
}
public void ThreadFunc ()
{
Networking.PopClient popClient = new networking.PopClient (cboServer.Text, txtUser.Text, txtPassword.Text);
bool bConnected = popClient.CreateConnection ();
if (!bConnected)
{
lblError.Text = popClient.LastError;
return;
}
int count = popClient.GetMailBoxCount ();
int size = popClient.GetMailBoxSize ();
lblMessageCount.Text = Convert.ToString (count);
lblQuotaUsed.Text = Convert.ToString (size);
} Like the comment there says, how can I use the popClient variable in both main and the threadfunc? So my other question (again like the comments say) is why isn't the thread started?
Thanks again for the help
- monrobot13
|
|
|
|
|
monrobot13 wrote:
Like the comment there says, how can I use the popClient variable in both main and the threadfunc?
It doesn't have to be static, but it can't be accessed while another thread is accessing it, or you'll get an InvalidOperationException.
I would suggest doing the popClient.DestroyConnection (); in the finally block in your ThreadFunc() procedure. This way, only your worker thread needs to use popClient during its lifetime.
Thread myThread = new Thread (new ThreadStart (ThreadFunc));
if (button1.Text == "Connect")
{
myThread.Start ();
button1.Text = "Disconnect";
}else{
myThread.Abort ();
myThread.Join ();
}
public void ThreadFunc ()
{
Networking.PopClient popClient = new networking.PopClient (cboServer.Text,
txtUser.Text, txtPassword.Text);
try{
bool bConnected = popClient.CreateConnection ();
if (!bConnected)
{
lblError.Text = popClient.LastError;
return;
}
int count = popClient.GetMailBoxCount ();
int size = popClient.GetMailBoxSize ();
lblMessageCount.Text = Convert.ToString (count);
lblQuotaUsed.Text = Convert.ToString (size);
}catch(Exception e){
}finally{
popClient.DestroyConnection();
OnFinished();
}
}
public event EventHandler Finished;
protected OnFinished()
{
if(Finished!=null)
Finished.BeginInvoke(this,EventArgs.Empty,null,null);
}
private void JobFinished(object sender, EventArgs e)
{
button1.Text = "Connect";
}
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
I'm using the following code to capture a screenshot :
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(GetDesktopWindow());
BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
GC.Collect();
return myImage;
I'm trying to capture a screenshot of the entire desktop and transferring it to a remote PC (to create a program like PcAnywhere). The thing is, i set my screenshot timer to something like 450 ms and on my machine (Athlon XP 2000+), it uses up around 30% of the CPU power. However, if i test it on my old P3-700 Mhz machine, the CPU utilisation is very high, ranging between 75-90%.
Is there any way to reduce the CPU utilisation (maybe like reducing the color depth of the image? but how)?
|
|
|
|
|
You should be releasing the DC you get with GetDC() , using ReleaseDC() , and if you aren't going to be using gr1 anymore, you should call Dispose() on it.
What's making it slow is probably the transfer, not the capturing. I don't know if this will make it faster, or slower, but you could make a new Bitmap with a lower color depth, create a Graphics from it, and use Graphics.DrawImage() to draw the image onto the new Bitmap .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
No, that doesn't make much difference. The code is now :
Image myImage = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height);
Graphics gr1 = Graphics.FromImage(myImage);
IntPtr dc1 = gr1.GetHdc();
IntPtr dc2 = GetDC(GetDesktopWindow());
BitBlt(dc1, 0, 0, Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, dc2, 0, 0, 13369376);
gr1.ReleaseHdc(dc1);
ReleaseDC(GetDesktopWindow(), dc2);
GC.Collect();
return myImage;
I fail to mention earlier that i am utilising a savejpgwithcompression function and after some checking, it appears that it is the cause of the problem. It could be the compression part, but it is essential to make the file size smaller. Here's the code :
private void SaveJPGWithCompressionSetting( Image image, string szFileName, long lCompression )
{
EncoderParameters eps = new EncoderParameters(1);
eps.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, lCompression );
ImageCodecInfo ici = GetEncoderInfo("image/jpeg");
image.Save( szFileName, ici, eps );
}
private ImageCodecInfo GetEncoderInfo(string mimeType)
{
ImageCodecInfo[] codecs = ImageCodecInfo.GetImageEncoders();
foreach (ImageCodecInfo codec in codecs)
{
if (codec.MimeType == mimeType){return codec;}
}
return null;
}
|
|
|
|
|
Well your first problem BitBlt is the slowest drawing technique. DirectX has BitBltFast or FastBitBlt which is twice as fast.
If your trying to accomplish fast rasterization your first problem is using the GDI. You should really use directX fucntionsin the framework or even just write c++ blocks in your cde and access the directx directly.
If possible create pages and store the bitmap data within the pages then show them at times needed
check out gamedev.net for a lot of pointers on graphics.
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
OK, so I have my main form 'Form1' and i'm in another class 'controls.cs' ...
How can I change the title of my main form 'Form1' from 'controls.cs' ??
I tired...
Form1 asdf=new Form1;
asdf.text="RESPECT THE ENG";
but that dosn't work. How can I do it?
/\ |_ E X E GG
|
|
|
|
|
adf.Text , not asdf.text .
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
well, actually I have this on controls.cs...
Form1 asdf = new Form1();
asdf.Text="RESPECT THE ENG";
now... the question i guess...
on Form1, how do I call this?
/\ |_ E X E GG
|
|
|
|
|
Form1 isn't an object. It's a class. asdf is an object (instance of a class). You need to change the text on asdf, not on Form1 and you can't do that unless you have a reference to asdf.
You might need to enumerate all the forms until you find the one you want or you could pass a reference of the form to control.cs so that you can manipulate it later.
|
|
|
|
|
try passing the form on the constructor of the control.cs object, and store this in the control object. i.e.
<br />
private Form form1;<br />
<br />
public Control(Form form)<br />
{<br />
this.form1 = form;<br />
}<br />
You should then be able to make calls like form1.Text = "whatever". If that doesn't work quite try public Control(ref Form form).
|
|
|
|
|
Anyway, which ever spelling you prefer is up to you. I just want to know this, how do you convert RGB values to hex values?
|
|
|
|
|
If you are wanting the web format (#RRGGBB), use ColorTranslator.ToHtml. Otherwise, use the Color.R, Color.G, and Color.B properties, and convert them to hex using Int32.ToString("xx").
"Blessed are the peacemakers, for they shall be called sons of God." - Jesus
"You must be the change you wish to see in the world." - Mahatma Gandhi
|
|
|
|
|
Hi,
I have a MDI application, which has a workspace (a form) and a tool bar window. User can create new forms and place controls from the tool bar onto this forms. They should be able to move controls on this form.
Here is the problem:
To let user move controls around on the form, I handle the MouseDown, MouseMove and MouseUp events for the selected control. In the MouseMove event handler I compute (using the location value saved in Mouse Down event) the new location for the control and set it as the location of the control. This somehow cause more mouse move events on the control - this is because, I think, the assignment of new value to the location property cause the control to move to the new location while it has the mouse pointer on it. This may generate new mouse move events!!!
Any suggestions / solutions to avoid the extra mouse move events would be highly appreciated.
Thanks,
Suhas
|
|
|
|
|
as long as the mouse moves, there will be mousemove events, try keeping track of when a control is being moved, using a boolean variable, and if its not being moved, then dont run all hte code in your MouseMove.
Another Post by NnamdiOnyeyiri l Website
|
|
|
|
|
I am sorry I do not understand your suggestion.
The control does not move on its own, it moves in response to mouse move events.
Even when the mouse has stopped moving the control continues to receive mouse move events because the control itself is moving in response to the previous mouse move events. I suspect that this extra mouse move events are generated because the control the has mouse pointer on it when it is moving.
The pseudo code is:
MyMouseMoveHandler()
{
// Compute the move distance
// Move the control - this itself it generating more mouse move events
// even though the mouse has stopped moving.
}
Thanks,
Suhas
|
|
|
|
|