|
Trance Junkie wrote: Now using this same code which works in vS 1.1 dont wanna update the UI label in net 2.0
What do u mean? throws an exception, hangs?
From what i know, you should never use a non UI thread to update the UI, it causes it to deadlock.
|
|
|
|
|
Hi thanks for the speedy reply
No, it does not even get an exception, nothing of that sort and it does not even hang. emmm
this is very strange....
|
|
|
|
|
It's not safe to access UI controls from threads other than the one they were created on. It mostly results in a freezing UI or other strange things. You're lucky nothing of this happened in your case. As there are many other people like you who weren't aware of this problem and accessed UI controls from other threads, it's no longer allowed. Use Invoke or BeginInvoke to update your label. This article[^] should help you.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook www.troschuetz.de
|
|
|
|
|
Thank you Stefan i`ll check out the article.
|
|
|
|
|
Richtextbox scenario:
Two RTB's with syncronized scrollbars. I get scrollinfo from the left and use that position to update RTB2 on the right. When i call SetScrollInfo for RTB2 the Scrollbar seems to move to correct position but it doesn't actually scroll down the text like it's neighbour on the left.
Can anyone tell me why or what I'm doing wrong?
|
|
|
|
|
Hello
SetScrollInfo doesn't actually scrolls. It changes the scrolling parameters as the name implies. Yes the little thumb moves up and down but it doesn't really scroll the content of the associated control. Revise the answer I posted to your earlier post, maybe it would help.
PS.
I guess you are using API calls? Why you jump low level that fast?
Regards
|
|
|
|
|
|
hello I have purchesed
the visual studio 2005
but I don't how the create an XML file.
does some one know how to create an XML?
|
|
|
|
|
Right click on your project in the solution explorer, add new item and select the XMLfile template. Or do you mean how to write in XML file?
BS
|
|
|
|
|
hi
i use access db and vs2005.
my problem is : i want in dataGridView_SelectionChanged event show fields of my database in some controls like textbox . i done this work and i gave good result . but when i delete a record in runtime the following error shown me:
Deleted row information cannot be accessed through the row.
i use datarow for add,update,delete row and use oledbdataadapter and use this
code to access fields of database and show it in some controls :
private void dataGridView1_SelectionChanged(object sender, DataGridViewCellPaintingEventArgs e)
{
if (this.BindingContext[ds_khane1, "Khaneh_1"].Position == -1)
return;
else
{
DataTable dt = ds_khane1.Tables["Khaneh_1"];
DataRow newrow = dt.Rows[dataGridView1.CurrentCell.RowIndex];
txt_name.Text = newrow["name"].ToString();
txt_family.Text = newrow["family"].ToString();
...
}note : i was use dataGridView1_CellPainting event and solved my problem,but why the above error shown me in dataGridView1_SelectionChangedevent and how to solve problem ?
thanks.
|
|
|
|
|
Hi all,
by making this.StartPosition = FormStartPosition.CenterScreen; works fine during design time, but when i change the size of form in load event, the form is not properly displayed in the center screen. eg.in the load event if i change the form's width and height. it did not display the form in the center screen, (ie upper left corner only centered with screen),
this is my code ( iam altering the forms width and height for the message to be displayed (custom messagebox)
private void CommnChkPopup_Load(object sender, EventArgs e)
{
this.Width = 460;
this.Height = 160;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable;
for (int len = 50; len < labelMessage.Text.Length; len = len + 50)
{
int i = labelMessage.Text.IndexOf("\n", (len - 50));
if (i > len || i == -1)
{
int j = labelMessage.Text.IndexOf(" ", len);
labelMessage.Text = labelMessage.Text.Insert(j, " \n");
}
}
if (this.Width < (labelMessage.Width + 92))
this.Width = labelMessage.Width + 92;
if (this.Height < (labelMessage.Height + 160))
this.Height = this.Height + labelMessage.Height;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.StartPosition = FormStartPosition.CenterScreen;
btnOk.Focus();
}
|
|
|
|
|
Hello
Here is a small code I wrote earlier to do the same thing:
Top = Screen.PrimaryScreen.WorkingArea.Height / 2 - Height / 2;
Left = Screen.PrimaryScreen.WorkingArea.Width / 2 - Width / 2;
Regards
|
|
|
|
|
i want to move a button on my form with mouse , it means that i want to Drag and Drop a button with mouse .
How could i do this?
|
|
|
|
|
Hello
You'd have to do it manually. Handle MouseDown to start dragging, MouseUp to stop dragging, and MouseMove to change the location of the buton according to the mouse new screen postion.
Regards
|
|
|
|
|
Hi nader
Thanks for your help .
could you please have a look at my code ,it works but not good ,when i want to drag , the button blinks more, and sometimes hide !!!
private void button1_MouseMove(object sender, MouseEventArgs e)
{
if (e.Button== MouseButtons.Left)
{
button1.Location = new Point(e.X, e.Y);
this.Update();
}
}
|
|
|
|
|
Your code is just fine. This is called flicker and it happens because these controls are not double buffered. Double buffering is a way of drawing things that has to be redrawn at fast rates. When you move the control, it redraws itself perhaps 20-30 times each second.
To make these controls double buffered you got two choices:
1- The easy way is to inherit from each and one of them and set Control.DoubleBuffred protected property to true -Yes this is the easy way-.
2- The hard way -if you don't like the inheritence-, is to use the BufferedGraphics class to customly draw your controls. Look it up in your local MSDN.
Here an article from MSDN on double buffering[^]
I hope this was useful.
Regards
|
|
|
|
|
Hi ,
what is the difference between abstract class & interface. how will you choose?
|
|
|
|
|
|
Hi
I have a strange problem.
There's a MdiForm that has a menu item on its main menu.
Here's its click event handler
<br />
private void ShowMyForm(object sender,EventArgs e)<br />
{<br />
MyForm frm=new MyForm();<br />
frm.MdiParent=this;<br />
frm.Show();<br />
}<br />
and it's working fine.
But when I want to replace this code with a command pattern , MyForm won't be added as a child of main form
Here's what I did:
<br />
public class ShowMyFormCommand:ICommand<br />
{<br />
Form mdiParent;<br />
public ShowMyFormCommand(Form mdiParent)<br />
{<br />
this.mdiParent=mdiParent;<br />
}<br />
public void Do()<br />
{<br />
MyForm frm=new MyForm();<br />
frm.MdiParent=this.mdiParent;<br />
frm.Show();<br />
}<br />
}<br />
then I replaced the code in event handler with this
<br />
private void ShowMyForm(object sender,EventArgs e)<br />
{<br />
new ShowMyFormCommand(this).Do();<br />
}<br />
Can you tell me what's wrong ?
Thanks
Nima H
|
|
|
|
|
Hello
Maybe I wasn't following the code correctly but in this line:
this.mdiParent=mdiParent
If the class ShowMyFormCommand is a memebr class of your form then this keyword will reference to your main form. Your main form doesn't have a MDIParent and thats why it should be null. So in the Do method
frm.MdiParent=this.mdiParent;
Your new form doesn't get an MDIParent because this.MDIParent should be null. Try to debug through the code to see if it's null or not.
Regards
|
|
|
|
|
Hi
Thank you for your kind reply.
I will debug my app.
|
|
|
|
|
Hi all,
Would someone please show me an example of how to use the post request in c#. I want to run a URL but when i use the following...
string Argu = "http://sms.co.za:5567/eapi/sub/send_sms/2/2.0?username=Whatever&password=BlahBlah&message=" + Convert.ToString(Message) + "&msisdn=" + Convert.ToString(CellNo);<br />
HttpWebRequest Request;<br />
StreamReader ResponseReader;<br />
Request = ((HttpWebRequest)(WebRequest.Create(Argu)));<br />
ResponseReader = new StreamReader(Request.GetResponse().GetResponseStream());
i get an error that says that the URI is to long...
Then i went to look for anything like this on the sms providers help files... i found this: "Please remember to URL-encode all parameters passed! Don't reinvent the wheel - rather use one of the countless libraries available. GET requests are allowed, but we strongly recommend using POST requests, especially if submitting a message to a large number of recipients (there can be limits on the size of GET requests)."
What does this mean...?
How do i use the POST request to run my variable that contains the URL: "Argu" without getting the error of the uri being too long.
Please help.
Thank you in advance...
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Basically, you create a web request with just the URL (no variables)
string Argu = "http://sms.co.za:5567/eapi/sub/send_sms/2/2.0"<br />
HttpWebRequest Request = ((HttpWebRequest)(WebRequest.Create(Argu)));
You tell it to use post
Request.Method = "POST";
Then you add each of your variables as header items
Request.Headers.Add("username","whatever");<br />
Request.Headers.Add("password","blah");<br />
Request.Headers.Add("message","hello world");<br />
Thats all typed by hand, so there might be some mistakes - should give you the idea though.
|
|
|
|
|
Would this:
Salon.Library.SystemDefault sysdef = new SystemDefault();<br />
sysdef.LoadData();<br />
ASCIIEncoding encoding = new ASCIIEncoding();<br />
string postData = "username=Whatever&password=BlahBlah&source_id=" + Convert.ToString(sysdef.ID) + "&message=" + Message + "&msisdn=" + CellNo;<br />
byte[] data = encoding.GetBytes(postData);<br />
<br />
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0?");<br />
myRequest.Method = "POST";<br />
myRequest.ContentType = "application/x-www-form-urlencoded";<br />
myRequest.ContentLength = data.Length;<br />
Stream newStream = myRequest.GetRequestStream();<br />
<br />
newStream.Write(data,0,data.Length);<br />
newStream.Close();
Am i doing this correctly? I saw this in an example on the net...
is this the same as the top part but the top part is the post part?
string Argu = "http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0?username=Whatever&password=BlahBlah&source_id=" + Convert.ToString(sysdef.ID) +"&message=" + Convert.ToString(Message) + "&msisdn=" + Convert.ToString(CellNo);<br />
HttpWebRequest Request;<br />
StreamReader ResponseReader;<br />
Request = ((HttpWebRequest)(WebRequest.Create(Argu)));<br />
ResponseReader = new StreamReader(Request.GetResponse().GetResponseStream());
Thank you in advance...
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|
|
Okay i got it to work with this code...
Salon.Library.SystemDefault sysdef = new SystemDefault();<br />
sysdef.LoadData();<br />
ASCIIEncoding encoding = new ASCIIEncoding();<br />
string postData = "username=Whatever&password=BlahBlah&source_id=" + Convert.ToString(sysdef.ID) + "&message=" + Message + "&msisdn=" + CellNo;<br />
byte[] data = encoding.GetBytes(postData);<br />
<br />
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://bulksms.2way.co.za:5567/eapi/submission/send_sms/2/2.0?");<br />
myRequest.Method = "POST";<br />
myRequest.ContentType = "application/x-www-form-urlencoded";<br />
myRequest.ContentLength = data.Length;<br />
Stream newStream = myRequest.GetRequestStream();<br />
<br />
newStream.Write(data,0,data.Length);<br />
newStream.Close();
But how do i know when an error occurs with this example...
Will this allow me to use more than 2083 caracters in the uri or will it give me an error like with the previous attempt to send the uri request with the get and not the POST. How can i test this, this method does not bring back errors...
"Many of life's failures are people who did not realize how close they were to success when they gave up." Thomas A. Edison
|
|
|
|