|
It looks like Mono’s Windows Forms still doesn’t work exactly like .NET’s Windows Forms.
Anyway… in the Popup.cs file, in method OnSizeChanged add "if (content != null)" checking… this fixes the NullReferenceException.
But the popups still don’t look very good because of bug in Mono, look here: http://go-mono.com/forums/#nabble-td22184714[^]
Łukasz
|
|
|
|
|
You may add this code as well to the Popup class, it fixes almost all bugs related to Mono.
protected override void OnLayout(LayoutEventArgs e)
{
Size suggestedSize = GetPreferredSize(Size.Empty);
if (AutoSize && suggestedSize != Size)
{
Size = suggestedSize;
}
SetDisplayedItems();
OnLayoutCompleted(EventArgs.Empty);
Invalidate();
} Łukasz
|
|
|
|
|
Thanks, great!
Any problem having this fix in .NET too or should the following be used?
public static bool IsRunningOnMono()
{
return Type.GetType("Mono.Runtime") != null;
}
protected override void OnLayout(LayoutEventArgs e)
{
if (IsRunningOnMono())
{
Size suggestedSize = GetPreferredSize(Size.Empty);
if (AutoSize && suggestedSize != Size)
{
Size = suggestedSize;
}
SetDisplayedItems();
OnLayoutCompleted(EventArgs.Empty);
Invalidate();
}
else
{
base.OnLayout(e);
}
}
I have not been able to fix my intended usage yet: CheckBoxComboBox uses an older version of Simple Popup, the test application itself is not working with Mono the plugin that uses CheckBoxComboBox has other issues too. Upgraded Simple Popup works slightly better.
/Gerhard
|
|
|
|
|
Checking for Mono would be good
private static bool? _isRunningOnMono;
public static bool IsRunningOnMono()
{
if (!_isRunningOnMono.HasValue)
_isRunningOnMono = Type.GetType("Mono.Runtime") != null;
return _isRunningOnMono.Value;
}
|
|
|
|
|
|
|
Hi,
I had a GroupBox which contain so many text boxes and labels alligned like a data entry form. i added one button and add this code in the button click.
ToolStripDropDown tspopUp = new ToolStripDropDown();
tspopUp.Margin = Padding.Empty;
tspopUp.Padding = Padding.Empty;
ToolStripControlHost host = new ToolStripControlHost(CategoryPanel);
host.Margin = Padding.Empty;
host.Padding = Padding.Empty;
tspopUp.Items.Add(host);
tspopUp.Show(GroupBox1,txtcategory.Location);
in a plain form if we add this, it will work nicely but if lot of control inside a form it will not popup. it's very bad.
How people told this code as excellent, i don't know.
Raj
|
|
|
|
|
Hi,
Well, you wrote to little I could help you. I've testes a form with 4 groupboxes, each of them contained 40 labels, 40 textboxes and 40 buttons, and all worked fine. Which version of .NET do you use? Have you installed latest service pack for the .NET you’re using?
Anyway… some time ago I’ve read an article which said that there is a bug in Windows Forms which occurs when there are very many controls on a Form. Maybe you had that “pleasure” to notice that bug. I don’t know.
Regards,
Łukasz
|
|
|
|
|
hai,
i am using the latest version to .net frame work. in my form i have lot of text boxes and label. i am added panel and trying to host that control in the toolstip host control. but it was not poping -up. After that i made it in a user control, then it start showing.
After this i implement this same user control in a DataGridView for populating data on clicking on the button in each row according to the key value in each row. But it disappointed me very much.Only once the data will get populate. next time onwards data is populating to the grid. but it's showing the frist populated data.
Can u check this dynamic databinding to a toolstripdropdown while clicking on each row of datagridview.
Raj
|
|
|
|
|
This is a very nice control, and was easy to setup and start using. I have a couple of questions about using this control as a tooltip, and I wonder if you have already done a similar project.
1. I was considering using this as a tooltip for a TreeView. I want to show a tooltip when hovering over each node. However, since a TreeNode is not a Control, and does not have a MouseLeave event, I tried to display the popup when the mouse is moved over the tree itself. This works to display the popup, but after the popup is visible the MouseMove event of the TreeView is no longer called. This makes it difficult to determine when to hide or redisplay the popup. Do you have any suggestions how to use this as a tooltip over a tree?
2. As a tooltip, it would be nice to have delay properties for display and redisplay like the ToolTip class. Have you given any thought to this?
|
|
|
|
|
Thank you, I am glad you like it.
1. Did you set FocusOnOpen property to false so the popup does not steal the focus? See the grid-example, I believe you want to achieve something similar.
2. Yes, time permitting I shall create a base class for tooltip.
Łukasz
|
|
|
|
|
After some testing, I was able to successfully create a custom tooltip over a treeview by using a Timer with the mouse events. The code looks something like this:
Class Variables
Popup toolTip;
CustomToolTip customToolTip;
Timer toolTipTimer = new Timer();
TreeNode toolTipNode = null;
Initialize Code
toolTip = new Popup(customToolTip = new CustomToolTip());
toolTip.AutoClose = false;
toolTip.FocusOnOpen = false;
toolTip.DropShadowEnabled = true;
toolTip.ShowingAnimation = toolTip.HidingAnimation = PopupAnimations.Blend;
toolTip.AutoSize = true;
toolTip.Resizable = true;
toolTipTimer.Interval = 1500;
toolTipTimer.Tick += new EventHandler(toolTipTimer_Tick);
tv.ShowNodeToolTips = false;
Events
int nStartX = 0;
int nStartY = 0;
int nLastX = 0;
int nLastY = 0;
void toolTipTimer_Tick(object sender, EventArgs e)
{
if (toolTipNode != null)
{
toolTipTimer.Stop();
customToolTip.TipText = toolTipNode.Text.Trim();
toolTip.Show(this, nLastX + 10, nLastY + 50);
}
}
private void tv_MouseMove(object sender, MouseEventArgs e)
{
TreeNode node = tv.GetNodeAt(e.X, e.Y);
if (node == null)
{
toolTipTimer.Stop();
if (toolTip.Visible)
{
toolTip.Close();
}
}
else
{
if (!toolTipTimer.Enabled)
{
toolTipNode = node;
toolTipTimer.Start();
nStartX = nLastX;
nStartY = nLastY;
}
else if ((e.X < nStartX-5) || (e.X > nStartX+5) || (e.Y < nStartY-3) || (e.Y > nStartY+3))
{
toolTipTimer.Stop();
if (toolTip.Visible)
toolTip.Close();
}
}
nLastX = e.X;
nLastY = e.Y;
}
private void tv_MouseLeave(object sender, System.EventArgs e)
{
toolTipTimer.Stop();
toolTip.Close();
}
This works nice to keep the tooltip displayed until the mouse is moved again. I might try a second timer to close the tooltip after a delay.
|
|
|
|
|
I’ve created a code which uses NodeMouseHover event instead of MouseMove. You may take a look at it:
public partial class Form1 : Form
{
public Form1()
{
Control.CheckForIllegalCrossThreadCalls = true;
InitializeComponent();
_popup = new Popup(_popupPanel = new Panel()
{
AutoSize = true,
AutoSizeMode = AutoSizeMode.GrowAndShrink,
BackColor = SystemColors.WindowFrame,
Padding = new Padding(0),
})
{
AutoSize = true,
FocusOnOpen = false,
};
_popupLabel = new Label()
{
AutoSize = true,
BackColor = SystemColors.Info,
BorderStyle = BorderStyle.FixedSingle,
Dock = DockStyle.Fill,
ForeColor = SystemColors.InfoText,
TextAlign = ContentAlignment.MiddleCenter,
};
_popupPanel.Controls.Add(_popupLabel);
_popup.Opened += (s, e) =>
{
object o = new object();
System.Threading.Timer timer = null;
Action close = () =>
{
if (_popupLabel.RectangleToScreen(_popupLabel.ClientRectangle).Contains(Cursor.Position)) return;
if (timer != null)
{
lock (o)
{
if (timer != null)
{
timer.Dispose();
timer = null;
_popup.Close();
}
}
}
};
_popupLabel.MouseLeave += (s2, e2) => close();
timer = new System.Threading.Timer((_) => Invoke(close), null, 2500, -1);
};
}
Popup _popup;
Panel _popupPanel;
Label _popupLabel;
private void treeView1_NodeMouseHover(object sender, TreeNodeMouseHoverEventArgs e)
{
_popupLabel.Text = e.Node.ToolTipText;
_popup.Size = _popupLabel.Size;
_popup.Show(treeView1.RectangleToScreen(e.Node.Bounds).Location);
}
} It’s only a draft, but finally I’ll create a base class for tooltips using this code.
Łukasz
|
|
|
|
|
I'm using this nice popup to pop a MonthCalendar inside a MaskedTextBox so that the user can enter or pick dates easily, the code is simple,but the popup's size is not enough to show the whole calendar(the proper should be (322,185) but it's now (178,155)).
Can somebody help me?
|
|
|
|
|
I have read the license agreement, and I am still wondering about some things.
As a contributor, the agreement states that all recipients of the software would be able to re-sell the software. Is this a misinterpretation? I would not be able to use this if all software that has this popup must be able to be reproduced and redistributed by buyers.
I do not fully understand the copyright requirements for software distributed without code.
Thank you for your help.
|
|
|
|
|
Paragraph 4 (commercial distribution) states that you may include the Popup in a commercial product (application), but as a creator of the popup I disallow embedding and/or re-selling this control in libraries/packages/component packs/etc.
So re-selling the Popup maybe is not prohibited by the CPL license, but by myself.
You can use of course the binaries in your software (or compile-in provided source code).
Regards,
Łukasz
|
|
|
|
|
Thank you for your quick response.
I was not looking to sell your popup as a featured item, but simply to use it in a distributed application. I had already made a popup control, and I was looking to add resizing capabilities when I found your control.
For use, it sounds like I will have to keep your control in its separate project, and derive off of it elsewhere for the specific functionality I need to add.
As far as copyrights, there was nothing in the license about including your copyright in the distributed application. This is what I will continue to assume unless informed otherwise.
Again, thank you for your response, and your work in making an excellent control.
|
|
|
|
|
You have to link your project to my dll file or use my original projects; if you include my code in your project or make changes to the code, you have to release the code under CPL license as well. So you're right, you should derive from it in another project to add specific functionality. You don't have to include copyright in the distributed application; besides, it's in the PopupControl.dll file's properties.
Here there is some "human-readable" information about CPL license: http://en.wikipedia.org/wiki/Common_Public_License[^]
I'm glad you like my control.
Regards,
Łukasz
|
|
|
|
|
Hello!
Nice control, thanks!
But, i develop app that must be crossplatform via Mono (2.4)
Mono Migration Analyzer (http://mono-project.com/MoMA[^]) says that only ONE ussue is present - invoke call of AnimateWindow.
It is very pity for me.
How do you think, is it possible to rewrite that function functionality on pure .NET code?
Thanks!
|
|
|
|
|
Well, I think it is possible, but it wouldn't be very easy, because it would require to 'mess' with custom regions. I've tried it once but finally I've replaced it with AnimateWindow API.
Regards,
Łukasz
|
|
|
|
|
I find it very useful
/PL01
|
|
|
|
|
Dzięki
|
|
|
|
|
Although It's a nice article, and I'm sure many will or already have found it helpful, I totally disagree with the concept.
Pop-up windows were developed many years ago, when there's no .NET, etc... and the idea and purpose was and for many still is very simple: to display a dialog, tooltip, info box, "put your name here" outside of the main application window, for informative purposes.
What you've presented in your article is changing the whole concept into something completely different (apart from tooltip control), and the whole idea is getting lost "somewhere".
1. I disagree that the popup window shouldn't steal focus from its parent. Who decided that popup windows shouldn't steal focus? Which windows is stealing focus and which isnt't depends on the situation and specific needs.
In fact, logically thinking, there should be only one control on the screen with focus - this is one of the principles of Windows programming. If you want do allow user to do something in your popup, like select something from combobox (one of the examples), then focus should migrate to that combobox and return it back when the popup is closed.
2. Popup windows are different from POP-UPs. POP-UPs are exploited by advertising companies to steal user's focus (attention) and display whatever they were created for. Popup windows are tools that should be used for specific purposes, mostly informative, like tooltips or contextual help. If they steal focus, it means that they seek/require user's attention, and this is by design.
3. Creating applications that leave users with few controls having focus at the same time on the screen is wrong and misleading.
Imagine disabled people using someone's software designed with such idea in mind, who's having troubles using it, because there's 5 popups on top of the window with focus - which have focus too (that's just one example).
I'd rather urge developers to learn proper UI design techniques, and treat such ideas with some distance, always trying to develop application with all people in mind (which doesn't mean they have to be ugly or not have fancy controls). You can't even imagine how many applications on the market are not suitable for disabled people, or people with little computer use knowledge - believe me - more than 75%.
So, summarizing: I still think this is nice article, and your idea is good, but has practical flaws.
I hope I didn't hurt anyone.
Cheers,
Gal
|
|
|
|
|
"develop application with all people in mind", really all people? I don't think so, I think Lukasz's pop-up control is cool enough.
set Popup control's AutoClose property as false can solve the problem of
stealing focus from its parent when the popup control showing, but it
is not easy to close the popup control automaticly. Is there a way to close
the popup control automaticly and don't stealing focus from its parent
when the popup control is showing?
|
|
|
|
|
Thank you for your constructive message.
Galatei wrote: 2. Popup windows are different from POP-UPs. POP-UPs are exploited by advertising companies to steal user's focus (attention) and display whatever they were created for. Popup windows are tools that should be used for specific purposes, mostly informative, like tooltips or contextual help.
I agree. I submitted an updated article in which I changed all occurrences of pop-up to popup since the article is not about ads.
Galatei wrote: 1. I disagree that the popup window shouldn't steal focus from its parent. Who decided that popup windows shouldn't steal focus? Which windows is stealing focus and which isnt't depends on the situation and specific needs.
In fact, logically thinking, there should be only one control on the screen with focus - this is one of the principles of Windows programming. If you want do allow user to do something in your popup, like select something from combobox (one of the examples), then focus should migrate to that combobox and return it back when the popup is closed.
3. Creating applications that leave users with few controls having focus at the same time on the screen is wrong and misleading.
Remember that the popup window should be a small part of a control/window, it should be light, so it could be treated like a real part of the control it belongs to (just like popup list of the combobox, popupmenu of the window), and as a part of that control it shouldn't steal "visual focus" (I explained it further). I admit that my example "more complex popup" is a little too complex for a popup window and it should either steal focus or be transformed into a dialog box. I also should've written that "not stealing focus" means only that the title bar of the window is not redrawn as an inactive (the "visual focus" is not stolen, but the actual focus is). The focus is only in one window at once, so if the popup is not a tooltip, but some interactive popup (like combobox list, menu, popup menu), and user clicks on that popup, the popup steals focus from the main window, but prevents the title bar from redrawing as inactive (or does not steal focus at all, just like popup menus don't).
Only the separate parts of the application (like other windows or dialog boxes) should steal focus from the main window. Well, that my personal opinion on that subject.
Galatei wrote: Imagine disabled people using someone's software designed with such idea in mind, who's having troubles using it, because there's 5 popups on top of the window with focus - which have focus too (that's just one example).
I'd rather urge developers to learn proper UI design techniques, and treat such ideas with some distance, always trying to develop application with all people in mind (which doesn't mean they have to be ugly or not have fancy controls). You can't even imagine how many applications on the market are not suitable for disabled people, or people with little computer use knowledge - believe me - more than 75%.
Hm... creating UI for disabled people can be tricky. It depends on the disablement (I hope it's the correct word). Personally, I always try to implement controls in way that they can be used either by mouse or by keyboard, but I don't if it's enough for disabled people.
I know that many applications are not suitable for people either disabled or with little knowledge. Many applications have terribly unclear or messed UI, because unfortunately some programmers think only about functionality, not usability.
It's great that Microsoft created UX Guide in which they explains how to create clear and usable UI. It should be read by every programmer which creates UI for Windows applications.
Once more, thanks for your post
Regards,
Łukasz
|
|
|
|
|