|
The expression new char[0] creates a new array of characters with the length zero.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
Ashfield wrote: It trims the null(s) off the end of string1.
Not really. It trims white space characters off the end of the string.
Despite everything, the person most likely to be fooling you next is yourself.
|
|
|
|
|
If you have something like this:
char[] trim = { 'o', 'a' };
textBox1.Text = "Hellooooo".TrimEnd(trim[0]);
TrimEnd will remove all 'o's from the end of your string, if you try to use TrimEnd like this:
textBox1.Text = "Hellooooo ".TrimEnd(new char[0]);
char[0] means whitespace and TrimEnd will remove all whitespaces from the end.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
If you call the TrimEnd method with an empty array, it will remove all white space characters from the end of the string.
This is a special case, that is not covered in the documentation. I have sent a message to Microsoft about it.
Update:
I got a reply from Microsoft, and they have updated the documentation.
Despite everything, the person most likely to be fooling you next is yourself.
modified on Thursday, November 6, 2008 6:33 AM
|
|
|
|
|
I have a checkbox field in the datagridview control as column 1 called "Select" as the name of the column.
When the user selects this checkbox for any row, I would like to run some code and based on an if statement to set this checkbox to false.
I am running this as follows but the checkbox is set to true i.e checked and can not change it to unchecked.
What am I doing wrong please?
private void dgv_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex >= 0)
{
if (dgv.Columns[e.ColumnIndex].Name.ToLower() == "select")
{
int intSecuritySetting = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells["SecuritySetting"].Value);
if (intSecuritySetting == 0)
{
//Make sure the security check is set to false...
dgv.Rows[e.RowIndex].Cells["Select"].Value = CheckState.Unchecked;
}
}
}
}
modified on Wednesday, November 5, 2008 4:06 AM
|
|
|
|
|
Hi arkiboys,
int intSecuritySetting = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells["SecuritySetting"].Value);
.Cells should be the int value instead of string
example:
int intSecuritySetting = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[e.ColumnIndex].Value
or
int intSecuritySetting = Convert.ToInt32(dgv.Rows[e.RowIndex].Cells[1].Value
hope this help
|
|
|
|
|
The value property gets updated after the cell click event and cellcontentclick event(atleast in the sample code I had written). Hence even if I change the checked state, it will again get changed. I wrote the same code in cellvaluechanged event and it works. Hope this helps.
|
|
|
|
|
Hi.
I'd like to know how to generate/create a specific number of components - buttons. The user would give out the number of buttons.
Every button should have its own working onclick code. And i could manipulate with every one of them whenever i want.
The creating part is partly know to me... but dont know how to control and rename them to get control for example ...
Button1 and button2 when i have buttons from 1-10.
Button1.Text="blah blah";
Button2.Text="the second butt.";
button3.Text="smthn";
etc.
Im really sorry if i have so many newbie questions but its just he way i am. Stil learning.
If there are any answers - i thank you for them
Have a nice day,
Matjaž
Força Barça!
|
|
|
|
|
hi,
Use for loop to create the button and add eventhandler for each button you create.Below is a sample:
{
InitializeComponent();
this.Load += new EventHandler(Form1_Load);
}
private void Form1_Load(object sender, EventArgs e)
{
Button[] b = new Button[3];
for (int i = 0; i < 3; i++)
{
b[i] = new Button();
b[i].Name = i.ToString();
b[i].Click +=new EventHandler(Form1_Click);
b[i].Location = new Point(i * 10, i * 10);
}
this.Controls.AddRange(b);
}
private void Form1_Click(object sender, EventArgs e)
{
Button b = (Button)sender;
Console.WriteLine(b.Name);
}
Hope this help
|
|
|
|
|
max00slo wrote: The user would give out the number of buttons.
void CreateButtons(int num)
{
Button[] button = new Button[num];
for (int i = 0; i < num; i++)
{
button[i].Click += new EventHandler(Buttons_Click);
this.Controls.Add(button[i]);
}
}
max00slo wrote: Every button should have its own working onclick code
void Buttons_Click (object sender, EventArgs e)
{
Button b = sender as Button;
switch (b.Name)
{
}
}
Hope I could understand you and could help
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Nice explain
|
|
|
|
|
Thank you
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
|
dear all,
I would like to know how can i detect the arrows key (left and right) when key press event handler in window application?
thanks in advance.
regards
cocoonwls
|
|
|
|
|
The KeyPress event is not raised by noncharacter keys; however, the noncharacter keys do raise the KeyDown and KeyUp events.
in KeyDown or KeyUp events you can detect arrows by e.KeyCode.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Simple. With ASCII Code.
lets take an example of pressing the keys in just form1:
if(e.KeyChar==37)<br />
txtStatus.Text = "You've pressed the left arrow key.";<br />
if(e.KeyChar==38)<br />
txtStatus.Text = "You've pressed the up arrow key.";<br />
if(e.KeyChar==39)<br />
txtStatus.Text = "You've pressed the right arrow key.";
This is just a small example to get you started and so that u get to know the use of ASCII char tables.
Edit: Well it would be, if it would work... kinda forgot how i used this stuff.
Heres a good link on explanating the keypress control:
http://msdn.microsoft.com/en-us/library/system.windows.forms.control.keypress(VS.71).aspx[^]
Greets,
Matjaž
Força Barça!
modified on Wednesday, November 5, 2008 1:54 AM
|
|
|
|
|
Hi Pedram Behroozi and max00slo,
I have tried it before, for other char is OK, but i just can't detect the arrows key.It never fire the keydown event. What i am do in my application is, i create the keydown event handler in one of my custom UI control, and it will pass the event args to one of my class via a abstract class.
any ideas are welcome.
thanks in advance
cocoonwls
modified on Wednesday, November 5, 2008 2:16 AM
|
|
|
|
|
cocoonwls wrote: i just can't detect the arrows key
Didn't this work?
if (e.KeyCode == Keys.Right)
{
...
}
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
Thanks for reply.
yes, i also try it .keycode, but still can't fix it..
|
|
|
|
|
You will need to override ProcessCmdKey method to catch the arrow key press.
|
|
|
|
|
Hi d@nish,
Can you please give me a simple explain on it, where should i put the override code, and should i add the virtual method on it(for override)?
thanks in advance
cocoonwls
|
|
|
|
|
You just need to override the method in your class. This VB.Net[^] code should get you going with it.
|
|
|
|
|
Thanks i got it!
|
|
|
|
|
you must derive a new class that is based on the class of the control that you want, and you override the ProcessCmdKey().
Syntax:
C#:
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
}
Full source code..C# Arrow Key Press
Vayne
|
|
|
|
|
I've got the following code that attaches a thumbnail image coming from an ImageList to a PictureBox. However, it is causing my application to not close once the code block gets executed. I suspect this has got to do with the resource(the photo file) not being released properly, I may be wrong though. Any experts advice would be greatly appreciated. All the best!
<br />
Image.GetThumbnailImageAbort myCallback =<br />
new Image.GetThumbnailImageAbort(ThumbnailCallback);<br />
Image myThumbnail = this.imageList1.Images[0].GetThumbnailImage(this.pictureBox1.Size.Width-5, this.pictureBox1.Size.Height-5, myCallback, IntPtr.Zero);<br />
<br />
this.pictureBox1.Image = myThumbnail;<br />
this.pictureBox1.SizeMode = PictureBoxSizeMode.CenterImage;
----------------------------------------------------------
"unzip; strip; touch; finger; mount; fsck; more; yes; unmount; sleep" - my daily unix command list
|
|
|
|