|
Show us what you have already then
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
for(int i=0;i<20;i++)
{
Button buttonName = new Button();
buttonName.property = property;
this.Controls.Add(buttonName);
}
Enjoy, add delegates for events!
|
|
|
|
|
thats exactly what i forgot
this.Controls.Add(buttonName);
thanks!
|
|
|
|
|
In the above example how would you modify the button's location in C#
for (int i = 0; i < 20; i++)
{
Button buttonName = new Button();
buttonName.Location.X = i * 20;
this.Controls.Add(buttonName);
}
When I try this I get an error message
Cannot modify the return value of 'System.Windows.Forms.Control.Location' because it is not a variable
I think I should have created an array of button pointers, but I can't remember how.
Thanks in advance
|
|
|
|
|
Just change
Douglas Kirk wrote: buttonName.Location.X = i * 20;
to
buttonName.Location = new Point(i * 20,whatever_you_want_as_y);
and you're done.
2+2=5 for very large amounts of 2
(always loved that one hehe!)
|
|
|
|
|
Hi,
if you know how to do things in Visual Designer (say position a button), then you can watch the code it generates (for a form myForm that would be in the InitializeComponents method inside file myForm.designer.cs).
So there is no magic involved, you can try and put similar code where ever you want, be it in the Form's constructor, load handler, a button click handler, you choose.
Apart from that, it helps to look up things in the documentation (use google to locate stuff) and to interpret compiler messages to the letter.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
I'm editing an existing library of user controls and I must admit, my experience is limited. These user controls are a combination of other user controls, mainly buttons and and panels. They where created to mimic the companies existing controls used in webapps for our desktop applications. Simple, and it works but they where initially designed for limited scalability.
So now the requirement emerges that each control should be resizable without altering the relative position of controls, some of which are transparent. I'm implementing this by, what appeared to be the easy task of reordering controls in the document outline and editing each controls dock and padding properties, which worked fine for a couple of controls.
Now I have the following outline: (control names reduced to simplicity to avoid confusion)
|---UserControl
|---Panel1
|---Panel2
|---Panel3
|---Button1
|---Button2
|---Button3
I dock Panel1 to DockStyle.Fill to the Parent UserControl to ensure that the control is resizable for obvious reasons, My problem is Panel2, which is overlayed on Panel1 by 6 pixels from the left and right respectively, I wish to keep this same fixed distance from the parent despite resizing, so I set dock to Fill and padding for left and right to 6 each, figuring this would work. It doesn't, which makes me feel I misunderstand the usage of Padding to begin with.
Any suggestions on where I went wrong and what would be the proper usage to enable this resizable implementation work as intended?
Sorry for weak explanation / poor ASCII art.
|
|
|
|
|
If you look into the anchor property instead of dock. that will do what you want and keep the 'indent'. Problem with the anchor is it may not work how you want it to if you have a lot of controls in the same control. i.e. 3 panels that need to have a 3rd of the form space each can not be handled with either dock nor anchor - that would need to be done manually on a resize event.
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Been trying, haven't had any luck. Any other suggestions? I want to fill but preserve a 6 pixel distance from the parent control (from the left).
|
|
|
|
|
anchor will def do it for that.
make sure the control has dock set to 'none'
then...
myControl.Anchor = AnchorStyles.Right | AnchorStyles.Left| AnchorStyles.Top| AnchorStyles.Bottom;
this will keep the control to fill but with the same distance from each side of its parent control as it was when first created.
if it don't work then you have some other issue stopping it working but i'm afraid i must leave the net for the time being. good luck
Life goes very fast. Tomorrow, today is already yesterday.
|
|
|
|
|
Got it, anchors where set already causing my dock to act weird, but i got it.
Thanks for the help
|
|
|
|
|
I'm lookin for a design-pattern that match what I need: I have class A which should hold a collection of class B or its inehrited classes. class B should be able to run functions and access properties on A and A should be able to run functions and access properties on B.
I've been suggested to pass reference of As properties to B opon construction, but I'm lookin for the design-pattern...
anyone know of any design-pattern similar to this?
Thanks alot
NaNg.
|
|
|
|
|
It's called the Charlie Foxtrot design pattern.
|
|
|
|
|
are you sure? (or are you just teasing me?) :x
I can't find in google some info about it.
Can you maybe give me a link for more info about it?
|
|
|
|
|
The word gullible is written on your ceiling. Check it out.
|
|
|
|
|
well excuse me for not having English as my native language and my day-to-day language
|
|
|
|
|
If they're that closely related they should implement a common interface that has the methods and properties that need to be shared in it.
public class A : C
{
}
public class B : C
{
}
public interface C
{
}
DaveBTW, in software, hope and pray is not a viable strategy. (Luc Pattyn) Visual Basic is not used by normal people so we're not covering it here. (Uncyclopedia) Why are you using VB6? Do you hate yourself? (Christian Graus)
|
|
|
|
|
i have a Winform application. I have a textbox in which as a user types in, I make calls to my server app to display the results in another box.
As the user types in quickly i am making a lot of calls in a short period of time. I would like to put a throttle like 2 secs for every time I hit the server. In this way if the user types in quickly i will be hitting the server with the latest input every 2 secs rather than for every keyword..
Any suggestions would be appriciated..
|
|
|
|
|
Queue the users input into a Queue, read the queue from a separate thread or a timer.
|
|
|
|
|
Hi,
you need a single timer for that; it will be used as a one-shot with 2 second interval.
1.
When the user enters something, start the timer (if not already running) and set its interval to 2000 msec. Don't call the server yet.
When the interval elapses, call the server and stop the timer (prevent it from firing periodically).
With this set-up you are getting something resembling a user-idle detector, with the disadvantage that a user typing 1 character a second won't get anything until he stops typing for at least 2 seconds.
2.
If you want intermediate server calls as well, on top of tbe above, note the DateTime.Now value of every user action and compare them with the time of the last server call.
3.
If you want no delay on first input, on top of the above, check for timer running; if not, call server.
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
This is the error:
{"An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: TCP Provider, error: 0 - A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.)"}
What is the solution?
|
|
|
|
|
SQL Server 2005 isn't configured to accept remote connections by default - you'll need to setup the server configuration correctly.
|
|
|
|
|
I have had this error on several occasions, all of them could be traced to my having incorrect parameters in the connection string. Not always the same parameter though.
So check the connection string for correctness.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Something to check before trying other things, open the Sql Server Configuration Manager, go to Protocols and ensure TCP/IP is enabled. It isn't by default...
Regards,
Rob Philpott.
|
|
|
|
|
are u trying to connect to a web database such as MySql on wwww.example.com?
|
|
|
|