|
Josh Smith wrote: Do you know what companies do with people who don't do their own work...they promote them!
Oh god he is telling the truth...Take my 5
|
|
|
|
|
http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2
|
|
|
|
|
Is it possible to open Shared Memory in a C# Windows application? specifically, Shared Memory created in a C++ app using the CreateFile, CreateFileMapping API.
(& if it is possible, can I get a hint where to start looking for the "instructions"?)
|
|
|
|
|
|
I used the flwing code to focus a control. But i got nothing. why?
private void button1_Click(object sender, EventArgs e)
{
if (lst1.Items.Count > 0)
{
lst2.Items.Add(lst1.SelectedItem);
lst1.Items.Remove(lst1.SelectedItem);
}
if (lst1.CanFocus)
{
lst1.Focus();
}
}
rgds,
stephen myint
|
|
|
|
|
There is an design paradox here: To have this event, you need to click the buttom which forces the focus onto the button. If it was anywhere else, you wouldn't be able to click the button.
You don't want things stealing focus while doing various operations (like clicking, drag-and-drop, etc) anyway. You should consider another UI design instead of trying to have focus jump around on the form while performing user input.
|
|
|
|
|
Use the form's Select() method or ActiveControl property instead.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
U can use Javascript client side scripting for setting focus
"Aim to go where U have never been B4 and Strive to achieve it"
http://groups.yahoo.com/subscribe/dotnetforfreshers
http://himabinduvejella.blogspot.com
|
|
|
|
|
Hello,
I want to add names coming from my database to be coupled to the Text of buttons.
The number of names is variabel (depending on grade of filtering).
So I wanted to build a loop for adding the names to the Text of the buttons.
<br />
for(i = 0; i < total; i++)
buttoni.Text = "corresponding name from tabel";<br />
The "corresponding name from tabel" is no problem, but I want the i from the for-loop to be used in the variabel name for the assignement of the text. (which you see very hard-coded in the code)
But I always get errors, no matter what i try ..
Can somebody help?
Allready thanks!
-- modified at 11:07 Wednesday 3rd May, 2006
|
|
|
|
|
What errors do you get?
Please read this
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
That doesn't really matter i think (i tried different things).
I just need a way to form a variabel with a part (button) and the content of a variabel (i), which makes button1, button2, button3, ..
The errors are like "The name 'buttoni' does not exist in the current context" but that seems pretty obvious I think ..
|
|
|
|
|
Have you tried something like:
int n = x; //x being your number of buttons
Button [] buttons = new Button[n];
//remember to create every button individually.
//so far it's just an array for holding buttons, but no individual buttons.
string [] buttonStrings = new string[n]; //or use your tabel
for(int i = 0; i < n; i++)
{
buttons[i] = new Button();
buttons[i].Text = buttonString[i];
}
-Larantz-
|
|
|
|
|
Hmm, that's not exactly what I'm looking for.
This is a sample:
<br />
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;<br />
for (int i = 0; i < totaal; i++)<br />
{<br />
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();<br />
}<br />
button[i] gives errors, also buttoni, button{i} etc.
Somebody?
|
|
|
|
|
JelleM wrote:
button[i] gives errors, also buttoni, button{i} etc.
Somebody?
button[i] is the right way to access an element of a button array. WHAT ERROR DO YOU GET!!! Copy/paste it out of the IDE.
|
|
|
|
|
I don't really understand what you mean ..
I haven't got an array, only seperate buttons which are created in the design-mode with names like button1, button2, etc.
|
|
|
|
|
If you know the names of the buttons then all you have to do is write a switch (or if/else) block and set the Text property of the button you wish (inside the loop).
--------------------------------------------------------
My portfolio & development blog
Q:What does the derived class in C# tell to it's parent?
A:All your base are belong to us!
|
|
|
|
|
Yeah, that would be the most obvious, but ..
If I have 50 buttons which have to get a name, it's quiet a job to write the code, and it's also a lot of useless code, because it would be much nicer/easier/etc. with just a loop.
+ the fact that you don't know how much buttons must be named ..
|
|
|
|
|
Loop through the forms control array, check each controls name. Im writing this in the forum so i'll need typo fixed.
for (i = 1; i <10; I++)
if (controls[i].name = "button" +i.ToString() )
controls[i].Text = "blah"
|
|
|
|
|
This sounds like the type of thing that people do in scripted languages, such as JavaScript. If that is where you are coming from, it's time to abandon that way of thinking because strongly typed (static) languages don't dance that funky jig.
What you could do is create a method like this:
public Button GetButtonByText( string text );
and make it search through the Controls on the form/page looking for a button with the specified text. But that is hacky and crass. You're much better off doing what the other replies mentioned: put the buttons into an array and index into it via the loop index.
Josh
|
|
|
|
|
It was just an idea how to solve my problem (it seemed logical to me)
But I didn't really get the array-thing, can you explain it in code?
ALlready great thanks!
|
|
|
|
|
You can't dynamically create variable names the way you want to. Instead, store references to the buttons in a collection and index into the collection to access a specific button.
/ravi
My new year's resolution: 2048 x 1536
Home | Music | Articles | Freeware | Trips
ravib(at)ravib(dot)com
|
|
|
|
|
Can you give a short example of what you mean?
Great thanks man!
|
|
|
|
|
Like I said before:
You can create an array of buttons. An array is a list of objects.
To do this, you add brackets '[]' when creating a variable, i.e button variable or integer variable.
int [] myInts = new int[2].
for(int i = 0; i < myInts.Length; i++)
myInts[i] = some integer value.
As for the code you need, you can do this:
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;
Button []buttonList = new Button[totaal];
for (int i = 0; i < buttonList.Length; i++)
{
buttonList[i] = new Button();
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
}
You'd also have to set the location for your new buttons, so there's plenty of neccessary code missing here. But it should give you an idea of how to create a dynamic array consisting of buttons.
Have you concidered using a ComboBox instead? Might be hard to place 100 buttons on a form.
I.e add a combobox to your form in designview and call it myComboBox.
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;
ArrayList listItems = new ArrayList();
for (int i = 0; i < totaal; i++)
{
listItems.Add(aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString());
}
myComboBox.DataSource = listItems;
-Larantz-
-- modified at 16:47 Wednesday 3rd May, 2006
|
|
|
|
|
Allready enormous thanks!
The reason why i don't use a listbox (i used one) is that it is some sort of cash register and a listbox is far from handy.
With this code:
int totaal = this.aanbodTableAdapter.CountFrisdranken().Value;<br />
Button []buttonList = new Button[totaal];<br />
<br />
for (int i = 0; i < buttonList.Length; i++)<br />
{<br />
buttonList[i] = new Button();<br />
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();<br />
}<br />
It still gives an error that the name "button" doesn't exist ..
I don't really get the part of the location of the buttons what you bring forward ..
I'm pretty new with these things ..
|
|
|
|
|
That code fails because you used 'button[i]' instead of buttonList[i].
button[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
should be replaced with
buttonList[i].Text = aanbodTableAdapter.GetFrisdranken().FindByid(i).ToString();
An array of buttons is like, uhm, a series of buttons. So you can't access the array directly as if it was a button. You must identify the specific button in the array that you want to use, by an identifier. In this case we identify it by the integer 'i'.
So when defining
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
you need to identify each of the buttons when you use them.
int totaal = 3;
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
myButtonList[0] = new Button();
myButtonList[1] = new Button();
myButtonList[2] = new Button();
myButtonList[0].Text = "Button1"
myButtonList[1].Text = "Button2"
myButtonList[2].Text = "Button3"
or even easier with for loop:
public class foo : System.Windows.Forms.Form
{
private System.Windows.Forms.Button []myButtonList = new Button[totaal];
private void InitializeButtonArray()
{
for(int i = 0; i < totaal; i++)
{
myButtonList[i] = new Button();
myButtonList[i].Location = new System.Drawing.Point(10 + i*10, 10);
myButtonList[i].Dock = System.Windows.Forms.DockStyle.Left;
myButtonList[i].Name = "Button" + i;
myButtonList[i].TabIndex = i;
myButtonList[i].Text = "Text from your table";
myButtonList[i].Click += new System.EventHandler(this.myButtonList_Click);
}
}
private void myButtonList_Click(object sender, System.EventArgs e)
{
}
}
-Larantz-
|
|
|
|