C# using FileOpendialogbox control within my form class - c#

I have a weird requirement. I need to use FileOpenDialogBox control within my form. I mean not as other window but as control of a form. I know many applicationss that doing it. How can I do it in C#?

Try this object I found on the web.

Related

how to display textBox control in MessageBox?

Any idea how to display textBox control in MessageBox.
I'm working on winforms projcet c#.
Thank you in advance.
You can't. MessageBox is a special container designed to only show a message and buttons. Instead, you can create your own Form with whatever controls you want, and use .ShowDialog() on it.
You can simply add an Input box from VB.NET into your C# project.
First add Microsoft.VisualBasic to your project References, then use the following code:
string UserAnswer = Microsoft.VisualBasic.Interaction.InputBox("Your Message ", "Title", "Default Response");
And that should work properly.
It will be better to add a new Form in you application which you can customize the way you want.
and just call it from where ever required.
you could create a classic win form that looks like a message box and opening it as a modal form
perhaps using Form.ShowDialog
more info at
http://msdn.microsoft.com/en-us/library/c7ykbedk.aspx
You cannot customise the MessageBox, its better you use a popup designed using Windows Form separately and use its instance to invoke.
customPopup popup = new customPopup();
popup.ShowDialog();
Place your controls on the popup form and set their access modifiers to public if you want to access the textboxes or labels etc in your previous form.
customPopup popup = new customPopup();
popup.msgLabel.Text= "Your message";
popup.ShowDialog();
As I know there is no way to do that.
You can create a winform change it's style to look like a MessageBox and add your own controls.
Yes, as krillgar mentioned,you should create your own form. And
1. Encapsulate the form in a static class or function, so you may just call MyMessageBox.Show().
2. The textbox should have readonly=true, so the end users won't be able to change the text displayed, while they could select text and copy to clipboard.
Regarding to item 2, I believe many Windows build applications and MS Office use such approach.
using Microsoft.VisualBasic;//add reference
var Password = Interaction.InputBox("Message", "Title" ,"information in textbox", -1,-1);
In the variable "password" it receives the information that is entered from the text box.
Remember to add the reference "Microsoft.VisualBasic" in the solution explorer
Solution in here, you can create windows form and design it, set form is dialog, when you call form, it is auto show. In form you design, you set value some parameter static where other class in project, but you should set when you close form design that, OK, come back form init call show dialog, you create interval call when have == null return call, when != null you stop call back and using parameter in class static it !

Accessing windows applications controls from class library c# windows application

i wanted to disable form control from class library, means i added one class named as clsInit method & i called this method when i'm loading the form in main project,so i need find the control which one i wanted to disable.
Is it possible to find loaded form controls in class library?
Form.Controls property is what you need.
You can pass the reference of your form into your library, and access its controls via Controls property.
You may create an object of your form, as:
MyForm frm = new MyForm();
...then select the controls to be disabled:
foreach (Control control in frm.Controls)
{
if(control.Name == "cboSomeDdn")
control.Enabled = false;
}
and then load the form (this one :
frm.Load()
or
frm.Show()
If this is a one form application, you may also set this as a starting point:
Application.Run(frm);
Please use this answer as a starting point and not as a copy-paste
solution. Also ensure to follow best-practices of development in the
language of your choice.
Hope this helps!
Vivek

Show an instance of a component class in main form in c#

If I add a component class to my project containing some common controls, how can I display an instance of it in a panel in my main form?
I use this to create an instance of my class:
Component test = new Component1();
where Component1 is the name of my Component class
Then how could I do something like:
panel1.Controls.Add(test); ?
Or is there a way to do this without using Panels?
You are using the wrong class. A Component cannot be a child of a panel or a form, it doesn't have a visual presentation. The missing Handle property is the important one.
You need a Control. Derive your class directly from Control or from one of the built-in control classes (Button, Label, etc). You'd do the latter if you want to customize their behavior and make it re-usable.
Then how could I do something like: panel1.Controls.Add(test); ?
This is the correct way.
Or is there a way to do this without using Panels?
You could add your control to something other than a panel; for instance, to the form itself: Controls.Add(test).

How can I get the reference to currently active modal form?

I am writing a small class for driving integration testing of a win form application. The test driver class has access to the main Form and looks up the control that needs to be used by name, and uses it to drive the test. To find the control I am traversing the Control.Controls tree. However, I get stuck when I want to get to controls in a dialog window (a custom form shown as a dialog). How can I get hold of it?
You can get a reference to the currently active form by using the static Form.ActiveForm property.
Edit: If no Form has the focus, Form.ActiveForm will return null.
One way to get around this is to use the Application.OpenForms collection and retrieve the last item, witch will be the active Form when it is displayed using ShowDialog:
// using Linq:
var lastOpenedForm = Application.OpenForms.Cast<Form>().Last()
// or (without Linq):
var lastOpenedForm = Application.OpenForms[Application.OpenForms.Count - 1]
I'm not sure if you can access controls on a pre-built dialog box; they seem all packaged together. You may have more luck building a dialog box of your own that does what you want it to do. Then you can access the .Controls inside of it.
Correct me if i'm wrong, though, it sounds as if you are possibly attempting to access the controls on the dialog form when it's not quite possible to.
What I mean is, ShowDialog will "hold up" the thread that the form was created on and will not return control to the application (or, your test class) until ShowDialog has finished processing, in which case your user code would continue on its path.
Try accessing or manipulating the controls from a separate thread (in this case, refactor the test driver class to spawn a separate thread for each new form that must be displayed and tested).

Calling .Parent from a form causes textbox problem, MDI

I want to make a form contained in another form. The problem is the application is already a MDI, and you can't nest MDI's.
If I do
childFrm.Parent = parentForm
some controls behave oddly. For example, if you click on the text in the textbox, usually the text cursor appears where you clicked, but it doesn't, it just goes to the end of the text.
Any suggestions?
Thanks,
Any particular reason why you can't host the content in a UserControl instead of a Form?
How about adding the child forms as owned forms to the MDI parent?
http://msdn.microsoft.com/en-us/library/system.windows.forms.form.addownedform.aspx
Look at SetWindowParent Windows API Call, and no you cannot use .Parent it won't work correctly as .NET itself doesn't support internally what you're wanting to do.

Categories