 |
|
 |
Can anyone suggest a way to get around not being able to use DateTimePicker control in Popup? If I click on the datetimepicker "dropdown" control, the datetimepicker "selection" control shows up. Then when I try to select a date with a mouse click, the popup disappears and the date doesn't even change.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
The popup control was just what I needed. I'm using it of info, warnings and temporal results.
Thank you!
-- Carl Kelley WinMetrics Corporation
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello,
Okay, there's a change I want to include into the popup control however I am struggling to justify the change is suitable for this control. Maybe you can guide me on this...
Once a popup control show itself it keeps a focus until user leaves and the focus is move onto another control. That's what popup control does, notify/show to user willingly when the need arises.
The way i used it was i made the popup control to become a mini data entry form, it pops up when a user selects a item amongst a list of items. Then user can quickly enter data and when the DropDownClosed event is invoke, it updates the changes back to the list. Here's the catch, I want to make sure the user want to commit to the change by having a ENTER button on the popup. When the ENTER is clicked, then do the changes. So, you can think of it like a modal dialog, because it will always pass back a DialogResult. This way you know for sure if the user wants to commit or not.
My question is do i create a method ShowDialog() for Popup.cs that add the modal dialog behavior to the popup? or should i just check for boolean variable instead (pseudo code is provided below)
eg.
Popup.Show();
// enter data into the popup
// popup_DropDownClosed() is called private void popup_DropDownClosed() { // check to see if the enter button is clicked if(isClicked) { // update changes } }
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
It seems to me an excellent job, but I can not develop an amendment to be able to recognize the event popup.Show(), from inside the UserControl. The event "MyBase.Load" makes loading only the first time it is open, as I need to be updated of those depending on data in some form or panel from which appears POPUP, and "… Handles popup.DropDown" understands that has been opened, but no good and then activate a function Shared contained in UserControl.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Great stuff. This is what I want to achieve in C-Sharp. Can someone provide Can somebody provide a C# version of this control.
Marsh
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
using System; using System.Collections.Generic; using System.ComponentModel; using System.Diagnostics; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
namespace Streamline.Windows.CommonControls { public partial class Popup : System.ComponentModel.Component { //Title: Display any usercontrol as a popup menu //Author: Pascal GANAYE //Email: pascalcp@ganaye.com //Environment: VB.NET 2003 //Keywords: Popup, Contextual, Menu, Tooltip //Level: Beginner //Description: This class let you show any usercontrol in XP style popup menu.
public Popup() : this(null, null) { }
public Popup(Control UserControl) : this(UserControl, null) { InitializeComponent(); }
public interface IPopupUserControl { bool AcceptPopupClosing(); }
public enum ePlacement : int { Left = 1, Right = 2, Top = 4, Bottom = 8, TopLeft = Top | Left, TopRight = Top | Right, BottomLeft = Bottom | Left, BottomRight = Bottom | Right } private bool mResizable = true; private Control mUserControl; private Control mParent; private ePlacement mPlacement = ePlacement.BottomLeft; private Color mBorderColor = Color.DarkGray; private int mAnimationSpeed = 150; private bool mShowShadow = true;
private PopupForm mForm;
//INSTANT C# NOTE: C# does not support optional parameters. Overloaded method(s) are created above. //ORIGINAL LINE: Sub new(Optional ByVal UserControl As Control = null, Optional ByVal parent As Control = null) public Popup(Control UserControl, Control parent) { mParent = parent; mUserControl = UserControl; }
public void Show() { // I use a shared variable in PopupForm class level for this ShowShadow // because the CreateParams is called from within the form constructor // and we need a way to inform the form if a shadow is nescessary or not PopupForm.mShowShadow = this.mShowShadow; if (mForm != null) { mForm.DoClose(); } mForm = new PopupForm(this); OnDropDown(mParent, new EventArgs()); }
// This internal class is a borderless form used to show the popup private class PopupForm : Form { public static bool mShowShadow; private bool mClosing; private const int BORDER_MARGIN = 1; private Timer mTimer; private Size mControlSize; private Size mWindowSize; private Point mNormalPos; private Rectangle mCurrentBounds; private Popup mPopup; private ePlacement mPlacement; private System.DateTime mTimerStarted; private double mProgress; private int mx; private int my; private bool mResizing; internal Panel mResizingPanel; private const int CS_DROPSHADOW = 0X20000; private static System.Drawing.Image mBackgroundImage; public delegate void DropDownEventHandler(object Sender, EventArgs e); public event DropDownEventHandler DropDown; public delegate void DropDownClosedEventHandler(object Sender, EventArgs e); public event DropDownClosedEventHandler DropDownClosed;
public PopupForm(Popup popup) { mPopup = popup; this.SetStyle(ControlStyles.ResizeRedraw, true); FormBorderStyle = FormBorderStyle.None; StartPosition = FormStartPosition.Manual; this.ShowInTaskbar = false; this.DockPadding.All = BORDER_MARGIN; mControlSize = mPopup.mUserControl.Size; mPopup.mUserControl.Dock = DockStyle.Fill; Controls.Add(mPopup.mUserControl); mWindowSize.Width = mControlSize.Width + 2 * BORDER_MARGIN; mWindowSize.Height = mControlSize.Height + 2 * BORDER_MARGIN; Form parentForm = mPopup.mParent.FindForm(); if (parentForm != null) { parentForm.AddOwnedForm(this); }
if (mPopup.mResizable) { mResizingPanel = new Panel(); //TODO: INSTANT C# TODO TASK: Insert the following converted event handlers at the end of the 'InitializeComponent' method for forms, 'Page_Init' for web pages, or into a constructor for other classes: mResizingPanel.MouseUp += new System.Windows.Forms.MouseEventHandler(mResizingPanel_MouseUp); mResizingPanel.MouseMove += new System.Windows.Forms.MouseEventHandler(mResizingPanel_MouseMove); mResizingPanel.MouseDown += new System.Windows.Forms.MouseEventHandler(mResizingPanel_MouseDown); if (mBackgroundImage == null) { System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(Popup)); mBackgroundImage = (System.Drawing.Image)(resources.GetObject("CornerPicture.Image")); } mResizingPanel.BackgroundImage = mBackgroundImage; mResizingPanel.Width = 12; mResizingPanel.Height = 12; mResizingPanel.BackColor = Color.Red; mResizingPanel.Left = mPopup.mUserControl.Width - 15; mResizingPanel.Top = mPopup.mUserControl.Height - 15; mResizingPanel.Cursor = Cursors.SizeNWSE; mResizingPanel.Anchor = AnchorStyles.Bottom | AnchorStyles.Right; mResizingPanel.Parent = this; mResizingPanel.BringToFront(); } mPlacement = mPopup.mPlacement; // Try to place the popup at the asked location ReLocate();
// Check if the form is out of the screen // And if yes try to adapt the placement Rectangle workingArea = Screen.FromControl(mPopup.mParent).WorkingArea; if ((mNormalPos.X + this.Width) > workingArea.Right) { if ((mPlacement & ePlacement.Right) != 0) { mPlacement = (mPlacement & ~ePlacement.Right) | ePlacement.Left; } } else if (mNormalPos.X < workingArea.Left) { if ((mPlacement & ePlacement.Left) != 0) { mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right; } } if (mNormalPos.Y + this.Height > workingArea.Bottom) { if ((mPlacement & ePlacement.Bottom) != 0) { mPlacement = (mPlacement & ~ePlacement.Bottom) | ePlacement.Top; } } else if (mNormalPos.Y < workingArea.Top) { if ((mPlacement & ePlacement.Top) != 0) { mPlacement = (mPlacement & ~ePlacement.Top) | ePlacement.Bottom; } } if (mPlacement != mPopup.mPlacement) { ReLocate(); }
// Check if the form is still out of the screen // If yes just move it back into the screen without changing Placement if (mNormalPos.X + mWindowSize.Width > workingArea.Right) { mNormalPos.X = workingArea.Right - mWindowSize.Width; } else if (mNormalPos.X < workingArea.Left) { mNormalPos.X = workingArea.Left; } if (mNormalPos.Y + mWindowSize.Height > workingArea.Bottom) { mNormalPos.Y = workingArea.Bottom - mWindowSize.Height; } else if (mNormalPos.Y < workingArea.Top) { mNormalPos.Y = workingArea.Top; }
// Initialize the animation mProgress = 0; if (mPopup.mAnimationSpeed > 0) { mTimer = new Timer(); // I always aim 25 images per seconds.. seems to be a good value // it looks smooth enough on fast computers and do not drain slower one //INSTANT C# NOTE: The VB integer division operator \ was replaced 1 time(s) by the regular division operator / mTimer.Interval = Convert.ToInt32(System.Math.Floor(1000f / 25f)); mTimerStarted = System.DateTime.Now; mTimer.Tick += new System.EventHandler(Showing); mTimer.Start(); Showing(null, null); } else { SetFinalLocation(); } Show(); mPopup.OnDropDown(mPopup.mParent, new EventArgs()); }
public static bool DropShadowSupported() { OperatingSystem os = Environment.OSVersion; return (os.Platform == PlatformID.Win32NT) & os.Version.CompareTo(new Version(5, 1, 0, 0)) >= 0; }
protected override System.Windows.Forms.CreateParams CreateParams { get { CreateParams parameters = base.CreateParams; if (mShowShadow && DropShadowSupported()) { parameters.ClassStyle = parameters.ClassStyle | CS_DROPSHADOW; } return parameters; } }
protected override void Dispose(bool disposing) { if (disposing) { if (mTimer != null) { mTimer.Dispose(); } } base.Dispose(disposing); }
private void ReLocate() { //int parent = 0; int rW = 0; int rH = 0; rW = mWindowSize.Width; rH = mWindowSize.Height; mNormalPos = mPopup.mParent.PointToScreen(new Point()); switch (mPlacement) { case ePlacement.Top: case ePlacement.TopLeft: case ePlacement.TopRight: mNormalPos.Y -= rH; break; case ePlacement.Bottom: case ePlacement.BottomLeft: case ePlacement.BottomRight: mNormalPos.Y += mPopup.mParent.Height; break; case ePlacement.Left: case ePlacement.Right: //INSTANT C# NOTE: The VB integer division operator \ was replaced 1 time(s) by the regular division operator / mNormalPos.Y += Convert.ToInt32(System.Math.Floor((mPopup.mParent.Height - rH) / 2f)); break; } switch (mPlacement) { case ePlacement.Left: mNormalPos.X -= rW; break; case ePlacement.TopRight: case ePlacement.BottomRight: // nothing break; case ePlacement.Right: mNormalPos.X += mPopup.mParent.Width; break; case ePlacement.TopLeft: case ePlacement.BottomLeft: mNormalPos.X += mPopup.mParent.Width - rW; break; case ePlacement.Top: case ePlacement.Bottom: //INSTANT C# NOTE: The VB integer division operator \ was replaced 1 time(s) by the regular division operator / mNormalPos.X += Convert.ToInt32(System.Math.Floor((mPopup.mParent.Width - rW) / 2f)); break; } }
private void Showing(object sender, EventArgs e) { mProgress = System.DateTime.Now.Subtract(mTimerStarted).TotalMilliseconds / mPopup.mAnimationSpeed; if (mProgress >= 1) { mTimer.Stop(); mTimer.Tick -= new System.EventHandler(Showing); AnimateForm(1); } else { AnimateForm(mProgress); }
}
protected override void OnDeactivate(System.EventArgs e) { base.OnDeactivate(e); if (mClosing == false) { if (this.mPopup.mUserControl is IPopupUserControl) { mClosing = ((IPopupUserControl)this.mPopup.mUserControl).AcceptPopupClosing(); } else { mClosing = true; } if (mClosing) { DoClose(); } } }
protected override void OnPaintBackground(System.Windows.Forms.PaintEventArgs e) { e.Graphics.DrawRectangle(new Pen(mPopup.mBorderColor), 0, 0, this.Width - 1, this.Height - 1); }
private void SetFinalLocation() { mProgress = 1; AnimateForm(1); Invalidate(); }
private void AnimateForm(double Progress) { double x = 0; double y = 0; double w = 0; double h = 0; if (Progress <= 0.1) { Progress = 0.1; } switch (mPlacement) { case ePlacement.Top: case ePlacement.TopLeft: case ePlacement.TopRight: y = 1 - Progress; h = Progress; break; case ePlacement.Bottom: case ePlacement.BottomLeft: case ePlacement.BottomRight: y = 0; h = Progress; break; case ePlacement.Left: case ePlacement.Right: y = 0; h = 1; break; } switch (mPlacement) { case ePlacement.TopRight: case ePlacement.BottomRight: case ePlacement.Right: x = 0; w = Progress; break; case ePlacement.TopLeft: case ePlacement.BottomLeft: case ePlacement.Left: x = 1 - Progress; w = Progress; break; case ePlacement.Top: case ePlacement.Bottom: x = 0; w = 1; break; } mCurrentBounds.X = mNormalPos.X + System.Convert.ToInt32(x * mControlSize.Width); mCurrentBounds.Y = mNormalPos.Y + System.Convert.ToInt32(y * mControlSize.Height); mCurrentBounds.Width = System.Convert.ToInt32(w * mControlSize.Width) + 2 * BORDER_MARGIN; mCurrentBounds.Height = System.Convert.ToInt32(h * mControlSize.Height) + 2 * BORDER_MARGIN; this.Bounds = mCurrentBounds; }
internal void DoClose() { try { mPopup.OnDropDownClosed(mPopup.mParent, new EventArgs()); } finally { mPopup.mUserControl.Parent = null; mPopup.mUserControl.Size = mControlSize; mPopup.mForm = null; Form parentForm = mPopup.mParent.FindForm(); if (parentForm != null) { parentForm.RemoveOwnedForm(this); } parentForm.Focus(); Close(); } }
private void mResizingPanel_MouseUp(object sender, System.Windows.Forms.MouseEventArgs e) { mResizing = false; Invalidate(); }
private void mResizingPanel_MouseMove(object sender, System.Windows.Forms.MouseEventArgs e) { if (mResizing) { Size s = Size; s.Width += (e.X - mx); s.Height += (e.Y - my); this.Size = s; } }
private void mResizingPanel_MouseDown(object sender, System.Windows.Forms.MouseEventArgs e) { if (e.Button == MouseButtons.Left) { mResizing = true; mx = e.X; my = e.Y; } }
protected override void OnLoad(System.EventArgs e) { base.OnLoad(e); // for some reason setbounds do not work well in the constructor this.Bounds = mCurrentBounds; } }
protected virtual void OnDropDown(object Sender, EventArgs e) { if (DropDown != null) DropDown(Sender, e); }
protected virtual void OnDropDownClosed(object Sender, EventArgs e) { if (DropDownClosed != null) DropDownClosed(Sender, e); }
#region Public properties and events
public delegate void DropDownEventHandler(object Sender, EventArgs e); public event DropDownEventHandler DropDown; public delegate void DropDownClosedEventHandler(object Sender, EventArgs e); public event DropDownClosedEventHandler DropDownClosed;
[DefaultValue(false)] public bool Resizable { get { return mResizable; } set { mResizable = value; } }
[Browsable(false)] public Control UserControl { get { return mUserControl; } set { mUserControl = value; } }
[Browsable(false)] public Control Parent { get { return mParent; } set { mParent = value; } }
[DefaultValue(typeof(ePlacement), "BottomLeft")] public ePlacement HorizontalPlacement { get { return mPlacement; } set { mPlacement = value; } }
[DefaultValue(typeof(Color), "DarkGray")] public Color BorderColor { get { return mBorderColor; } set { mBorderColor = value; } }
[DefaultValue(true)] public bool ShowShadow { get { return mShowShadow; } set { mShowShadow = value; } }
[DefaultValue(150)] public int AnimationSpeed { get { return mAnimationSpeed; } set { mAnimationSpeed = value; } } #endregion
internal System.Windows.Forms.PictureBox CornerPicture;
} }
namespace Streamline.Windows.CommonControls { partial class Popup { /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.IContainer components = null;
/// <summary> /// Clean up any resources being used. /// </summary> /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param> protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }
#region Component Designer generated code
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Popup)); this.CornerPicture = new System.Windows.Forms.PictureBox(); ((System.ComponentModel.ISupportInitialize)(this.CornerPicture)).BeginInit(); // // CornerPicture // this.CornerPicture.Image = ((System.Drawing.Image)(resources.GetObject("CornerPicture.Image"))); this.CornerPicture.Location = new System.Drawing.Point(17, 17); this.CornerPicture.Name = "CornerPicture"; this.CornerPicture.Size = new System.Drawing.Size(100, 50); this.CornerPicture.TabIndex = 0; this.CornerPicture.TabStop = false; ((System.ComponentModel.ISupportInitialize)(this.CornerPicture)).EndInit();
}
#endregion } }
-- Carl Kelley WinMetrics Corporation
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
 |
please tell me how to write this code with C#
specifically i'm unable to understand mPlacement = (mPlacement And Not ePlacement.Top) Or ePlacement.Bottom
please help me out
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Several people asked me whether they can put this library in their application.
This article and the code attached is Public Domain. So you can use it, in any application including a commercial application.
You can make changes to the code, you don't have to make the source public.
You don't have to report your modifications and you don't have to credit me. You are encouraged to send me or in this forum any feedback or bug fix you might have found but is not an obligation.
I hope it clarify the situation.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I would like to congratulate you for authoring this control, this is really awesome, simply marvelous!
How do you come up with such ideas, and how do you execute them, is it because you are really good with the language?
Regards,
Blumen
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
I would like to make your control to suit my needs. I know you may or may not reply this message. I am hoping you do reply, and my question is how to modify your control to allow point focus and activated on parent control when the popup is showing.
For example,
(C#) ListBox listbox = new ListBox(); listbox.Width = 200; listbox.Height = 200; popup = new Popup(listbox, textBox1); // textBox1 is a regular Textbox
The way I want to use the control is to emulate search box on Google.com or MSN.com, when the user types inside a textbox, a corresponding search result showing in listbox display.
Right now, your control seems to retain focus and prevent the user from typing on the textbox.
And, can i ask you (or someone on codeproject) to show me how to show the popup while allowing the focus to be on parent control.
Ray
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
u may check this http://www.codeproject.com/useritems/simplepopup.asp but only disadvantage is you don't have the resize option. but its a neat solution to solve the focus problem. vishnu
Vishnu
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hi,
thanks for this code - it's great...
One question - how can I make it popup on custom coordinates, for example inside a textbox, using Cursor.Position?
Thanks in advance!
Kiril.
|
| Sign In·View Thread·PermaLink | 5.00/5 |
|
|
|
 |
|
|
 |
|
 |
Hi Me and My team is developing an ERP System and find that your source is helpful. We were wondering if there are any restrictions in using your source? We plan to build a dll from it and use it with the Project. Please let us know if there are any restrictions and if so let us know what we can do to use it.
Bernard
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
How can you avoid the black flickering when showing the popup with popup.Show() with popup.opacity < 1.0f?
DoubleBuffered=true (in usercontrol) doesnt help here
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
 |
I was just browsing around and ran up on your code. I downloaded it and tried it out. I really like it. It has kind of gave me an idea of how do something that I have been trying to gigure out. You know how you have pinned controls in Visual Studio, for instance the toolbox, if it is unpinned it will collapse when it loses focus. I have been wanting to implement this same behavior in one of my apps for a while in order to increase real-estate on my form. Thanks for sharing the code and nice work.
-Jason
|
| Sign In·View Thread·PermaLink | 2.00/5 |
|
|
|
 |
|
|
 |
|
|
 |
|
 |
I am a beginner.I couldn't understand the interface IPopupUserControl.In the sub: Protected Overrides Sub OnDeactivate(ByVal e As System.EventArgs) MyBase.OnDeactivate(e) If mClosing = False Then If TypeOf Me.mPopup.mUserControl Is IPopupUserControl Then mClosing = DirectCast(Me.mPopup.mUserControl, IPopupUserControl).AcceptPopupClosing() Else mClosing = True End If If mClosing Then DoClose() End If End Sub I have questions as follows: 1、I don't know In any case the type of mUserControl would equal IPopupUserControl 2、I think that AcceptPopupClosing is never been set value,because there is no value was endowed with it. I would really appriciate if you tell me.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
 |
Hello Great control. You can use ControlPaint.DrawSizeGrip in ResizingPanel_Paint event instead of a picture.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |
|
|
 |
|
 |
Is there any way to get the parent form to retain its focused appearance? When the pop-up appears, the parent form title bar greys out, unlike behaviour when a combo drops down or a menu opens.
|
| Sign In·View Thread·PermaLink | |
|
|
|
 |