|
Hi,
In win forms you can add a control inside a panel using something like in the example below.
Suppose you have created a user control named MyUserControl and you have a panel on your form named PanelControls
private void FormMain_Load(object sender, System.EventArgs e)
{
MyUserControl c = new MyUserControl();
PanelControls.Controls.Add(c);
}
Hope that helps you.
Do your best to be the best
|
|
|
|
|
You've missunderstand me.
Adding controls to a panel or any control container control isn't an issue.
I asked can I somehow load a control from file name like I can do in asp.net with LoadControl function?
I have stored modules in xml file and in xml file is also where which controls has to be placed in which control container, so I have to read from xml to add a control to a control container.
In asp.net I will do that by storing the file name to the module (control) and then use the code below:
Control c = this.LoadControls("control path");<br />
c.ID = "what ever";<br />
ControlContainer.Controls.Add(c);
I want the same functionalaty in win forms, if this is possible, and if is, how?
I hope you understand...
Thanks.
|
|
|
|
|
Greetings!
I have a set of 6 RadioButtons, one of which is set based on a user-selection in a ListBox on the same form.
What I want to do is to disable the other 5 RadioButtons after the user makes the selection and one RadioButton is set.
I'm assuming that a collection is the best way to do this, so I can write some code that disables every RadioButton that is not the one that is selected.
Could you help me define this Collection? I've looked through MSDN and pages online but I'm a little confused about how one defines a collection.
Thanks!
|
|
|
|
|
In page_load or where you initialize your variables do:
List<RadioButton> buttons = new List<RadioButton>();
buttons.Add(RadioButton1);
buttons.Add(RadioButton2);
buttons.Add(RadioButton3);
buttons.Add(RadioButton4);
buttons.Add(RadioButton5);
buttons.Add(RadioButton6);
Then you can iterate throug them with loops:
foreach (RadioButton rb in buttons)
{
if(!rb.Checked)
rb.Enabled = false;
}
|
|
|
|
|
|
I have a form with a tabControl with two pages. On the second tab page is a textbox(txtMLBox_ID). I need to reference it from a module in another part of the application but can't seem to get the reference syntax correct.
Namespace: LabelTool
Form: MainForm (also in LabelTool ns)
tabControl: tabControl1
tabPage: tabMultiRuncard
textbox: txtMLBox
Attempting to access from:
MultiLotRC.cs which is also in the LabelTool ns
I thought that MainForm.tabControl1.txtMLBox.ToString() would work but I'm pretty rummy from trying every purmutation I can think of.
This probably is not a difficult as I'm making it. Progamming in C# (vs2005)
TIA
Tom Hamilton
|
|
|
|
|
I believe the controls generated by the designer is marked as private, which means if you want to access it from somewhere else you need to create a property that returns your control.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
Thank you Edbert,
(I'm very new to Object Oriented) Are you suggesting I do the get/set for a property then reference it?
Tom Hamilton
|
|
|
|
|
Yep. Do a get property (I don't think you need to create a set property) in order to be able to access the control within the form.
Otherwise you can also change the control's Modifiers through the form designer from private to public.
Hope that helps.
"A democracy is nothing more than mob rule, where fifty-one percent of the people may take away the rights of the other forty-nine." - Thomas Jefferson
"Democracy is two wolves and a lamb voting on what to have for lunch. Liberty is a well-armed lamb contesting the vote." - Benjamin Franklin
Edbert
Sydney, Australia
|
|
|
|
|
I have a form wich was divided into 16 pictureboxes. There is absolutly no room beetwen each other or them and the form. When i enlarge them they all enlarge downwards and to the left So the ones on the bottom and left side of the form, when they get enlarged, only a part of them appear(the left up side) how do i correct this??
rzvme
|
|
|
|
|
You can set the anchor properties to set how they resize when you resize your form.
Overall, I'd say you'd have more control if you drew your own bitmaps, although using a picturebox is certainly easier.
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
i'm not resizing the form...i just want to resize them when an event is fired
rzvme
|
|
|
|
|
practicly, how do i change the direction (from down right to up left) of enlarging for a picture box?
rzvme
|
|
|
|
|
I've been looking at remoting and creating test projects. Assuming that it it unacceptable to post the complete method implementation library on the client, the choices are to start with an interface, so that only the interface posts on the client while the server gets the complete method, or to use soapsuds to extract a proxy from the method library, which then posts on the client in place of the complete method.
I'm also looking at serialization, usually to receive a serialized data object back from the remote method, and client activation.
What I'm finding is that serialization only works along with using the an interface on the client, and client activation only along works with using a proxy (soapsuds) on the client.
This means that it is impossible to use both client activation and serialized data objects in a remote method unless the complete remote method implementation is posted on both the client and the server.
Have I missed anything? Appreciate if anyone can confirm that this is true or not.
|
|
|
|
|
Chuck Bevitt wrote: unless the complete remote method implementation is posted on both the client and the server.
A remoting object must exist in both processes (machines). Therefore "all" of it is in both locations. However you can use the remote object as a bridge or facade by putting the actual processing in an isolated library and class. Then the second library, containing the processing code, need not be installed on the proxy (client) machine.
Is that what you mean?
led mike
|
|
|
|
|
Hello,
I wrote some code for using some buttons in my application which depending on the state can be one of the 3 images:
- image_button_mouse_over.png (mouse is over my button)
- image_button_mouse_norma.png (mouse left my button)
- image_button_mouse_clicked.png (button clicked or mouse down)
I used the events (mouse_enter/mouse_leave/mouse_up/mouse_down/mouse_clicked) and depding on that and appropiate image is set to the button. IT WORKS FINE untill.. I click a button which display any window/dialog/whatever, when I do this the button stays after the click in the normal state (LIKE IT SHOULD BE), but when I close the window/dialog it remains in the image_button_mouse_over state even when I put into my code
<br />
button_clicked(object sender,eventargs e)<br />
{<br />
button1.Image=image_button_mouse_norma_handler;<br />
dialog.ShowDialog();<br />
button1.Image=image_button_mouse_norma_handler;<br />
}<br />
I checked and the mouse_leave event is fired, right after the showdialog() is lunched, but It doesnt change anything... Any Ideas ?
|
|
|
|
|
First of all, you really should encapsulate this behaviour, so you can set the bitmaps on button1 ( please tell me it's not called that ), and it will draw itself properly.
Second, perhaps your form needs to redraw itself, what if you call Invalidate() ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
I'm guessing here, but could it be that at some point in closing the window/dialog (which was opened by clicking the button) a mouse_enter message is getting set to the button, but since the mouse is not *actually* over the button, it never gets a mouse_leave message?
Have you tried working the GotFocus and LostFocus events into your overall logic?
-- modified at 16:06 Wednesday 4th October, 2006
|
|
|
|
|
i have done a handler for the file system watcher event.
ok, inside it, i wanna move a file (which generated the event) to another location, but when this event is fired the windows system is still copyng (which is worse) or moving the file in question and i can`t perform such task because the file is being used by another process (the windows system).
i have put a Thread.Sleep() in my code to wait for the copy, but it isn`t a cool way to solve this (it`s unpredictable). if i remove the Thread.Sleep() i`ll end up with an exception.
is there another way to solve this?
thanks
here`s the code snippet:
<br />
private void fileSystemWatcher_Created(object sender, System.IO.FileSystemEventArgs e)<br />
{<br />
try<br />
{<br />
if (pedido.CarregarArquivo(e.FullPath))<br />
{<br />
System.Threading.Thread.Sleep(60000);<br />
if (File.Exists(Path.Combine(caminhoDestinoSucesso, e.Name)))<br />
File.Delete(Path.Combine(caminhoDestinoSucesso, e.Name));<br />
File.Move(e.FullPath, Path.Combine(caminhoDestinoSucesso, e.Name));<br />
<br />
}<br />
else<br />
{<br />
System.Threading.Thread.Sleep(60000);<br />
<br />
if (File.Exists(Path.Combine(caminhoDestinoErro, e.Name)))<br />
File.Delete(Path.Combine(caminhoDestinoErro, e.Name));<br />
<br />
File.Move(e.FullPath, Path.Combine(caminhoDestinoErro, e.Name)); <br />
}<br />
}<br />
catch (Exception ex)<br />
{<br />
MostrarMensagem(ex.Message, true);<br />
}<br />
}<br />
|
|
|
|
|
I've encountered this problem as well. FileSystemWatchers have some inherent issues with them. This is the probably one of the more annoying ones. The events that fire off of the watcher are not necessarily after the file system has finished with the file. Furthermore, it can send multiple events for a single file copy/etc.
Now, to overcome this issue myself, I've done two things.
1) Wrote a generic class with an internal timer that buffers events. It captures an event and stores off the time of the event, updating duplicate events where necessary. At a set interval, the timer fires on the events that have elapsed a set time to an external body.
2) When accessing the files, I have a while loop that tries to access the file a set number of times. It catches any exceptions that might occur and then sleeps. Rinse and repeat.
I found that most of the issues that would cause exceptions are avoided via the first part of the solution, while the second just handles the lag time between completing the last writes to the file and releasing it. It seems to work out pretty good, if you need the generic class I can pass that on.
As a side tip, I would watchout for FileSystemWatchers because they seem to break down when any two FileSystemWatchers end up watching the same directory (which can easily occur if you include sub-directories).
Good luck.
|
|
|
|
|
hey andrew, thanks for your response...
in the meanwhile i have found a CP article about this issue (check it out at: http://web6.codeproject.com/cs/files/rrfilewatch.asp?df=100&forumid=31158&exp=0&fr=26[^])
but, unfortunally, it didn't sound so simple.
i'll try to master this code, and, if i don't succeed, try your second workaround. BTW, what have you done to access the file and catch the exception?
i think there's not anyway to solve this without using time elapses, after all.
also, if i have caught, your first idea has the same effecta as a Thread.Sleep() statement, doesn't it?
and any code would be appreciated! :]
|
|
|
|
|
That is essentially equivalent to the first part of the solution I was talking about. And yes, they do achieve the same result, but you end up throwing exceptions (which are costly for performance), if you just used Thread.Sleep.
I would add that if you were to have more than one file that you're specifically watching for, it looks like his implementation would produce a timer for each. The code I have derives from the FileSystemWatcher and uses the buffer I was talking about earlier to produce the desired result. But, that code should suffice for the most part. Email me if you would want to see the code I have.
|
|
|
|
|
hey andrew... i have done the following:
bool ok = false;<br />
do<br />
{<br />
try<br />
{<br />
File.Move(e.FullPath, e.FullPath);<br />
ok = true;<br />
}<br />
catch<br />
{<br />
Thread.Sleep(1000); }<br />
} while(!ok);
it`s working, but the program sleeps more than expected.
i can`t figure out exactly why. i have put the code in the event file system watcher event handler, so `e` refers to System.IO.FileSystemEventArgs.
any improvements?
|
|
|
|
|
Well, its because you're moving the file back into its same location and firing the event again I assume from the FileSystemWatcher. Then, because you're doing that within the event handler, it causes it to repeat the process forever.
I would first ask you this:
1) Are you attempting to monitor only one file at most?
2) Will the file be modified across a network potentially?
If the file is being updated across a network, you can quickly get numerous events called due to the fact that the file is written in chunks and each chunk fires off an event.
3) Are you attempting to move the file into another location, which will not produce an event?
The FileSystemWatcher has an internal buffer, which if too many events occur within a set amount of time, it will be overrun. Meaning, you'll lose events that you should have received. The best way to avoid this is to fire off another thread (ThreadPool works great here) to handle the job. If what you're doing is pretty minimal within the event handler or you're not handling too many files at a time, this should not be an issue. But I just wanted to make you aware of that problem.
|
|
|
|
|
I am having a strange problem that I have been unable to solve.
Basically, I am doing a DllImport on an unmanaged DLL that I have written, called "config.dll". This DLL is a bunch of C code compiled under a project in VS2005. This is all in a seperate solution.
When I place the DllImport into my C# project, it works fine as long as the config.dll is located in a different folder than the one the C# project is running from (and the DLLImport statement points to the other folder). I have also tried hardcoding the path of the DllImport statement to the directory of the C# project, either through "c:\\test\\config.dll" or ".\\config.dll", and these both give the same result as just "config.dll".
My failing DllImport:
[DllImport("config.dll", CallingConvention=CallingConvention.Cdecl)]
My working DllImport:
[DllImport("c:\\otherdir\\config.dll", CallingConvention=CallingConvention.Cdecl)]
The exception I get is (xxx.dll is the c# project):
An unhandled exception of type 'System.BadImageFormatException' occurred in xxx.dll
Additional information: An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
Any help or things for me to check would be appreciated!
Thanks,
David
|
|
|
|