Making a popup modal (containing a Custom UserControl) - c#

I'm looking at updating some existing code and making a popup modal which contains a custom user control and wondering if this is possible?
I know if I was to place the custom UserControl inside another form this could be achieved quite easily but this seems a bit overkill.
(CommentBox is the custom control)
CommentBox comment = CommentManager.GetComments(commentType, foreignID);
.//Some code to determine location of the popup
.
.
Popup popup = new Popup(comment);
popup.Show(grid.PointToScreen(viewerLocation));

If it has to be modal, then you have to use a form.
If you are just needing it to pop up over the form, then look into ToolStripDropDown and ToolStripControlHost to provide that ability. Here is an example: Padding/ Size / Margin, when using ToolstripControlHost for a popup control

Related

How to fill MDIForm with default content in c#?

I have created MDIForm that contains some child forms. Now i want to load some default content in MDIForm because without any content it is not looks good while opening MDIForm just like
.
When i tried to make some contents in MDIForm then the child form are behind the controls like
.
I tried load a child form in MDIParent form but it occurs some issues like i set form border style none, but it display minimize, maximize and close buttons. It affects on my designing & controls position too, but i can manage it using dock/anchor but the problem is form border style(as you can see in image2).
So please someone tell me that what is the right way to do this?
I hope you understand what i want to say. If you have doubt then you can ask me about that.

How to prevent popup, new tab, new window and message boxes in webbrowser control?

Here is HTML code :
<script type='text/javascript'>//<![CDATA[
window.onload=function(){
alert('hi');
}//]]>
</script>
Not only alerts, popups, new tab, new window but anything cause focus change.
By other words I don't want WebBrowser control to get focused or change current focus.
Looking for a solution that doesn't hurt any weppage( I need javascript enabled).
In theory, you should implement IProtectFocus, but apparently there're issues with it:
http://social.msdn.microsoft.com/Forums/windows/en-US/211733a0-af84-4cc4-9851-2f19def7aedd/iprotectfocus-and-allowfocuschange-not-working-on-webbrowser?forum=winforms
Another option might be to implement a CBTHook, handle HCBT_SETFOCUS and reject it (return 1 to prevent it) if the window becoming focused is a child window of the WebBrowser object.
Disclaimer: I myself haven't tried either of the above.

Best way to go about replacing forms?

I'm trying to make an application where the users can click on the buttons to navigate through different forms. I.E: If I click on network status, it replaces the Main Form with a network status form, and then you can go back to the main form by clicking on "return".
What would be the best approach to do this? I'm thinking panels but people told me to use usercontrol and I'm not quite familiar with it. I'd appreciate any guidance.
Looking on the post don't see any reason for non having just another Form.
Why do not just create another, fully functional Form, and hide "source" Form.
Can create some, sort of forms linked list structure, where you have (say)
public class MyAppForm : Form
{
MyAppForm _prev...
MyAppForm _next...
}
In this way where (say) Go to next button clicked, we hide original, pick and show _next.
Just an idea. You may change it in a way to make it simplier or fit better your app needs.
Hi,
Assuming your requirement as depicted in the storyboard. Have a UserControl of these many controls which are DOCKED as per the picture on the UserControl. Now in the blank area you will have to show / hide your page / form / screen.
I would suggest this piece of code can do the trick for you to display / hide form dynamically on navigation. Have this in your navigation bit i.e. Next / Prev click on the Usercontrol -
form.Location = new Point(leftPaneControl.Width , BannerControl.Height);
form.Size = new Size(this.Width - leftPaneControl.Width, this.Height - BannerControl.Height);
form.Anchor = AnchorStyles.Bottom | AnchorStyles.Top | AnchorStyles.Left |
AnchorStyles.Right;
this.Controls.Add(form);
On Next and Prev clicks , you just do Controls.RemoveByKey(...) to hide the existing form & the above code will add the next respective form after you have instantiated the same. This is a pretty cool function to remove control[s] from a collection if you have defined unique names for all your forms / screen / page [whatever you say].
This approach / design will allow you to just focus on designing your
pages / screens because creating this Usercontrol is a one-time
activity. After that you will only design your individual navigation pages / screens one by
one.
You could use several forms where ever needed and Show and Hide them as required.
You might also consider using something like MDI forms, where you can have one parent form that could host your menus, status and other bars.

Is their something like iframe in C#?

Is their something like iframe in c#?
I want to build an application with one form that its content changes according to the actions I do, like messenger live. The part when I log in and log out its too different "windows" but it happens in the same form.
There is no iframe equivalent in winforms or wpf, but there are ways to deal with it.
For either winforms or wpf, what you want to do is have a Panel which you change the content of.
A panel is a container which holds/encapsulates other controls.
If you have two different views you want to toggle between, create two panels at the same position with the content you need. Then you will show one and hide the other. When the user executes some action which requires you to change the view, then simply hide the displaying panel, and unhide/show the other one.
Think of it as layers, where you will only show one at a time.
You can also dynamically load user controls into a panel, much like an iframe, but I find it easier to have the content in the form, and hide/show as needed.
Assuming WinForms, how about using UserControls? Place as many as you want in a single/multiple forms, and interact as you do in forms. See, UserControl class.
You can load a form into a Panel or tabPage from a TabControl:
Form f = new Form();
f.TopLevel = false;
panel1.Controls.Add(f);
f.Show();
f.Dock = DockStyle.Fill;

WPF/C# Add new style pop up form

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.

Categories