I've build an email app in c# winforms with a richtextbox.
Now I want to add a search option, which opens in a new Window to enter the search/replace text.
I know how to do this in one form, but how do i get access to the richtextbox in form1 from the second form?
In short, to have a form return values, one must give it public properties, and have them set by the form when closing.
A more in-depth explanation and examples can be found here
Related
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 !
I am developing an application in C#. I have a Main Form where I have some buttons that give the user the possibility to start a new form into the Main Form.
When there are more of this kind of forms opened and the user choose to minimize one, it goes to back behind all opened forms. So if the user would want to open again that form he must close/minimise all forms.(for beeing able to see the minimized one)
How can I manage the minimised form location so it could be visible after it is minimised? I tried without any result stuff like that: bringToFront, Activate, Focus, etc.
My Main Form contains the buttons and a panel, so the forms are opening in the panel bellow the buttons.
why don't you go for MDI win-form ? I think they fit really well in what you are trying to achieve
http://msdn.microsoft.com/en-us/library/ms973874.aspx
Finally I did managed myself to solve the problem. It was so simple.
For the forms that opens in the panel child I removed
formName.Dock = DockStyle.Fill;
and I set the formName.Height = panelContainer-25; So now the little form minimized is visible.
I know this is late post but might be useful for someone like me.
Try this this was working for me to set minimized window location and size as well
https://social.msdn.microsoft.com/Forums/windows/en-US/d6014e48-2adb-4096-8bea-94c2f3b1c47c/how-to-change-the-location-of-a-minimized-mdichild-form?forum=winforms
I have an application in C# that I am converting to Java, specifically the C# version consists of a Windows Form (Main Form) that spawns a new form (Secondary Form) via the ShowDialog() method.
The event handler for a button (OK) on the Secondary form sets it's DialogResult to OK when clicked, therefore in the Main Form I can check what DialogResult was set and retrieve data from the Secondary Form instance through properties.
I'm using SwingUI with NetBeans and I was wondering how I would go about implementing the same functionality in the Java application.
An example:
The Box to be displayed (Secondary Form):
The behaviour for the Secondary Form:
Then a simple piece of code in the Main Form to get the results:
As you can see it doesn't really take a lot of effort to achieve this in C#, how big of a task would it be to do it in Java?
Thanks for your time.
A dialog that returns a String:
String s = (String)JOptionPane.showInputDialog(
frame,
"Complete the sentence:\n"
+ "\"Green eggs and...\"",
"Customized Dialog",
JOptionPane.PLAIN_MESSAGE,
icon,
possibilities,
"ham");
Taken from the Swing Dialog tutorial. You can create a more complex dialog by subclassing the JDialog class and creating accessor methods to get the data.
Edit for those who say to use tab control
I would love to use a tab control; yet i have no idea how to go about linking the tab control up from the main form. I would assume that I would have to do something like this:
Create Form with a blank TabControl on it, no pages created.
Create a CustomuserControl (Add -> user Control), with my controls on it.
When a new chat comes in, create a tab control Item, Tab Control Page, add the Custom Control to the Tab Control Page. Add the tab control handle to the hash table, so that when new messages come in, they can be referenced in the proper control.
But, i am so not sure how to do this. For example, I know that I can create custom events inside of the User Control, so that, for example, if each control has a 'bold' button, i can each page that has that control on it, to actually USE the button.
Yet i also need to register message callbacks, so that I can use a MessageGrabber to send data to it, and tha'ts not assigned inside of the UserControl, that's assigned programatically when a new window comes in; but since I have no controls to reference, i can't assign.
KISS Philosophy
Wouldn't it be easier to just create the form, like i do now, and then just dock that form within a window or something? So that, in essence, it's still creating the form, but it's also a separate window?
Original Question
Okay, so i'm stumped (which isn't that big of a surprise when it comes to complex C# logic lol)! What i'm trying to do is the following:
Goal: Setup tabbed chatting for new chat application.
Completed: Open new window whenever a chat message is received, or a user requests a new chat from the roster. This is working perfectly, and opens only a window when the user doesn't already have the chat open. Nice and happy there.
Problem: I dont want windows. Well, i do want A window, but, i do not want tons of separate windows. For example, our Customer Service team may have about 10 active IM windows going at one time, i do not want them to have to have 10 windows tiled there lol. I'd rather they have a single Private IM window, and all 10 tabs docked within the window.
Logic: This is my logic here, which may be flawed, i do apologize:
OnMessage: Open new chat window if one doesn't already exist; if one exists, open it as a tab within the current chat window.
SendMessage: ^^ ditto ^^
Code Examples:
if (!Util.ChatForms.ContainsKey(msg.From.Bare))
{
RosterNode rn = rosterControl1.GetRosterItem(msg.From);
string nick = msg.From.Bare;
if (rn != null)
nick = rn.Text;
frmChat f = new frmChat(msg.From, xmpp, nick);
f.Show();
f.IncomingMessage(msg);
return;
}
Note on above: The Util. function just keeps tracks of what windows are opened inside of a hashtable, that way, when messages come in, they route to the proper window. That is added with the:
Util.ChatForms.Add(m_Jid.Bare.ToLower(), this);
Command in the frmChat() form.
Library in Use: agsxmpp from: http://www.ag-software.de/agsxmpp-sdk/download/
Problem:
How can i convert this code to open inside of tabs, instead of windows? Can someone please give me some ideas, and help with that. I just can't seem to wrap my head around that concept.
Use TabControl
Quick question: I have a very busy form going on that I have developed for information about say book records.
I want to design an 'add new book form' that is essentially a pop up to input the info. What is the best way to do this? Use a Usercontrol that is called on a button click or menu click? an entire new form?
Have seen this type of functionality, but never designed it in a pop up have just had user input info on the actual form - and it can get very busy.
Thanks for any help. Cheers!
I'd follow a common UI idiom. Which is, from a menu choose "new". This would popup a modal dialog to accept information about the new book form. I'd use the "Popup" control for this dialog. Within this Popup control, I'd embed the actual input dialog which is implemented as a user control.
The popup control is part of the .Net framework. If you can't see the control in the VS2008 designer, then you can still use it by typing the Popup element directly in the text view of the .xaml file.