public void Panel_AutoSizeMode_SetWithHandle_GetReturnsExpected(AutoSizeMode value) { using var control = new SubPanel(); Assert.NotEqual(IntPtr.Zero, control.Handle); int invalidatedCallCount = 0; control.Invalidated += (sender, e) => invalidatedCallCount++; int styleChangedCallCount = 0; control.StyleChanged += (sender, e) => styleChangedCallCount++; int createdCallCount = 0; control.HandleCreated += (sender, e) => createdCallCount++; control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); }
internal static void SetAutoSizeMode(IArrangedElement element, AutoSizeMode mode) { BitVector32 state = GetLayoutState(element); state[_autoSizeModeSection] = mode == AutoSizeMode.GrowAndShrink ? 1 : 0; SetLayoutState(element, state); }
protected override void OnDrawItem(DrawListViewItemEventArgs e) { if (e.ItemIndex == this.AnimateItemIndex && this.View == View.LargeIcon) { AutoSizeMode aa = this.GetAutoSizeMode(); Size sz = e.Item.ImageList.ImageSize; Point loc = new Point(e.Bounds.Location.X + (e.Bounds.Width - sz.Width) / 2, e.Bounds.Y); RectangleF rcf = new RectangleF(loc, sz); if (bmpAnimate == null) { bmpAnimate = this.CreatDefaultBmp("Loading...", Color.Wheat, Color.Green); } Graphics g = Graphics.FromImage(bmpAnimate); g.DrawImage(this.animatedImage, new RectangleF(0, bmpAnimate.Height - animatedImage.Height, bmpAnimate.Width, animatedImage.Height)); g.Dispose(); //Image img = this.CreatDefaultBmp(this.animatedImage,thumbBorderColor,SystemColors.ControlText); e.Graphics.DrawImage(bmpAnimate, rcf); RectangleF rcText = this.GetItemRect(e.Item.Index, ItemBoundsPortion.Label); StringFormat sf = (StringFormat)StringFormat.GenericTypographic.Clone(); sf.Alignment = StringAlignment.Center; sf.FormatFlags = StringFormatFlags.NoClip | StringFormatFlags.FitBlackBox; e.Graphics.DrawString(e.Item.Text, e.Item.Font, SystemBrushes.ControlText, rcText, sf); } else { e.DrawDefault = true; base.OnDrawItem(e); } }
public void SplitterPanel_AutoSizeMode_SetWithParent_GetReturnsExpected(AutoSizeMode value) { using var parent = new Control(); using var control = new SplitterPanel(null) { Parent = parent }; int layoutCallCount = 0; control.Layout += (sender, e) => layoutCallCount++; int parentLayoutCallCount = 0; parent.Layout += (sender, e) => parentLayoutCallCount++; control.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); Assert.False(parent.IsHandleCreated); Assert.Equal(0, parentLayoutCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); Assert.False(parent.IsHandleCreated); Assert.Equal(0, parentLayoutCallCount); }
public void Button_AutoSizeModeGetSet(AutoSizeMode expected) { var button = new Button(); button.AutoSizeMode = expected; Assert.Equal(expected, button.AutoSizeMode); }
public void Panel_AutoSizeMode_Set_GetReturnsExpected(AutoSizeMode value) { var panel = new Panel { AutoSizeMode = value }; Assert.Equal(value, panel.AutoSizeMode); }
public void Button_AutoSizeModeGetSetInvalid(AutoSizeMode expected) { var button = new Button(); // act & assert InvalidEnumArgumentException ex = Assert.Throws <InvalidEnumArgumentException>(() => button.AutoSizeMode = expected); Assert.Equal("value", ex.ParamName); }
private void SetMenuProperties(bool autoSize, AutoSizeMode autoSizeMode, Color backColor, Color transparencyKeyColor, DockStyle dock, FormBorderStyle formBorderStyle, bool showInTaskBar) { this.AutoSize = autoSize; this.AutoSizeMode = autoSizeMode; this.Dock = dock; this.ShowInTaskbar = showInTaskBar; FormBorderStyle = formBorderStyle; }
/// <summary> /// Sets the automatic size mode. /// </summary> /// <param name="control">The control.</param> /// <param name="value">The value.</param> public static void SetAutoSizeMode(this Panel control, AutoSizeMode value) { if (control.InvokeRequired) { control.BeginInvoke(new MethodInvoker(() => control.SetAutoSizeMode(value))); } else { control.AutoSizeMode = value; control.Refresh(); } }
public void TabPage_AutoSizeMode_Set_GetReturnsExpected(AutoSizeMode value) { var page = new TabPage { AutoSizeMode = value }; Assert.Equal(AutoSizeMode.GrowOnly, page.AutoSizeMode); // Set same. page.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, page.AutoSizeMode); }
public void SplitterPanel_AutoSizeMode_Set_GetReturnsExpected(AutoSizeMode value) { using var control = new SplitterPanel(null) { AutoSizeMode = value }; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.False(control.IsHandleCreated); // Set same. control.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.False(control.IsHandleCreated); }
public void TabPage_AutoSizeMode_SetWithParent_GetReturnsExpected(AutoSizeMode value) { var parent = new TabControl(); var page = new TabPage { Parent = parent, AutoSizeMode = value }; Assert.Equal(AutoSizeMode.GrowOnly, page.AutoSizeMode); // Set same. page.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, page.AutoSizeMode); }
public void Panel_AutoSizeMode_SetWithParent_GetReturnsExpected(AutoSizeMode value) { var parent = new Control(); var panel = new Panel { Parent = parent, AutoSizeMode = value }; Assert.Equal(value, panel.AutoSizeMode); // Set same. panel.AutoSizeMode = value; Assert.Equal(value, panel.AutoSizeMode); }
public Label() : base() { TextAlign = StringAlignment.Near; VerticalAlign = StringAlignment.Center; ForeColor = Color.Black; BackColor = Color.Transparent; Font = new Font(Fonts.Fonts.Collection.ByName("Arial Rounded MT Bold"), 10); Text = this.Name; //let auto-size grow the label AutoSize = true; AutoSizeMode = AutoSizeMode.GrowOnly; Width = 1; Height = 1; }
public void Panel_AutoSizeMode_Set_GetReturnsExpected(AutoSizeMode value) { using var control = new SubPanel { AutoSizeMode = value }; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); // Set same. control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); }
public void Panel_AutoSizeMode_SetWithParent_GetReturnsExpected(AutoSizeMode value, int expectedLayoutCallCount) { using var parent = new Control(); using var control = new SubPanel { Parent = parent }; int layoutCallCount = 0; control.Layout += (sender, e) => layoutCallCount++; int parentLayoutCallCount = 0; void parentHandler(object sender, LayoutEventArgs e) { Assert.Same(parent, sender); Assert.Same(control, e.AffectedControl); Assert.Equal("AutoSize", e.AffectedProperty); parentLayoutCallCount++; } parent.Layout += parentHandler; try { control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); Assert.False(parent.IsHandleCreated); Assert.Equal(expectedLayoutCallCount, parentLayoutCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); Assert.False(parent.IsHandleCreated); Assert.Equal(expectedLayoutCallCount, parentLayoutCallCount); } finally { parent.Layout -= parentHandler; } }
public void Panel_AutoSizeMode_Set_GetReturnsExpected(AutoSizeMode value) { using var control = new SubPanel(); int layoutCallCount = 0; control.Layout += (sender, e) => layoutCallCount++; control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.False(control.IsHandleCreated); Assert.Equal(0, layoutCallCount); }
public Vector2 AutoSize(AutoSizeMode autoSize, Content.ContentPool content, Vector2 size, Vector2 maxSize, System.Windows.Forms.Padding padding) { if (autoSize == AutoSizeMode.Full) { var fi = content.Peek <FontImplementation>(Font); var ts = fi.TextSize(Text); return(ts + new Vector2(padding.Horizontal, padding.Vertical)); } else { int textHeight; var f = BuildGlyphs(content.Peek <FontImplementation>(Font), Orientation.TopLeft, maxSize, Text, out textHeight); float w = 0, h = 0; if (f != null) { foreach (var g in f) { h = Math.Max(h, g.Position.Y + g.Size.Y); w = Math.Max(w, g.Position.X + g.Size.X); } } if (autoSize == AutoSizeMode.Vertical) { return(new Vector2(size.X, h + padding.Vertical)); } else if (autoSize == AutoSizeMode.Horizontal) { return(new Vector2(w + padding.Horizontal, size.Y)); } else if (autoSize == AutoSizeMode.RestrictedFull) { return(new Vector2(w, h) + new Vector2(padding.Horizontal, padding.Vertical)); } else { throw new ArgumentException(); } } }
public ControlAutoSizeTester (Size customPrefSize, AutoSizeMode autoSizeMode) { custom_prefsize = customPrefSize; AutoSizeMode = autoSizeMode; }
public void SplitterPanel_AutoSizeMode_SetWithHandleWithParent_GetReturnsExpected(AutoSizeMode value) { using var parent = new Control(); using var control = new SplitterPanel(null) { Parent = parent }; Assert.NotEqual(IntPtr.Zero, parent.Handle); int invalidatedCallCount = 0; control.Invalidated += (sender, e) => invalidatedCallCount++; int styleChangedCallCount = 0; control.StyleChanged += (sender, e) => styleChangedCallCount++; int createdCallCount = 0; control.HandleCreated += (sender, e) => createdCallCount++; int layoutCallCount = 0; control.Layout += (sender, e) => layoutCallCount++; int parentInvalidatedCallCount = 0; parent.Invalidated += (sender, e) => parentInvalidatedCallCount++; int parentStyleChangedCallCount = 0; parent.StyleChanged += (sender, e) => parentStyleChangedCallCount++; int parentCreatedCallCount = 0; parent.HandleCreated += (sender, e) => parentCreatedCallCount++; int parentLayoutCallCount = 0; parent.Layout += (sender, e) => parentLayoutCallCount++; control.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); Assert.Equal(0, layoutCallCount); Assert.True(parent.IsHandleCreated); Assert.Equal(0, parentInvalidatedCallCount); Assert.Equal(0, parentStyleChangedCallCount); Assert.Equal(0, parentCreatedCallCount); Assert.Equal(0, parentLayoutCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(AutoSizeMode.GrowOnly, control.AutoSizeMode); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); Assert.Equal(0, layoutCallCount); Assert.True(parent.IsHandleCreated); Assert.Equal(0, parentInvalidatedCallCount); Assert.Equal(0, parentStyleChangedCallCount); Assert.Equal(0, parentCreatedCallCount); Assert.Equal(0, parentLayoutCallCount); }
public void Panel_AutoSizeMode_SetWithCustomLayoutEngineParentWithHandle_GetReturnsExpected(AutoSizeMode value, int expectedLayoutCallCount) { using var parent = new CustomLayoutEngineControl(); using var control = new SubPanel { Parent = parent }; int layoutCallCount = 0; control.Layout += (sender, e) => layoutCallCount++; int parentLayoutCallCount = 0; void parentHandler(object sender, LayoutEventArgs e) { Assert.Same(parent, sender); Assert.Same(control, e.AffectedControl); Assert.Same("AutoSize", e.AffectedProperty); parentLayoutCallCount++; }; parent.Layout += parentHandler; Assert.NotEqual(IntPtr.Zero, parent.Handle); int invalidatedCallCount = 0; control.Invalidated += (sender, e) => invalidatedCallCount++; int styleChangedCallCount = 0; control.StyleChanged += (sender, e) => styleChangedCallCount++; int createdCallCount = 0; control.HandleCreated += (sender, e) => createdCallCount++; int parentInvalidatedCallCount = 0; parent.Invalidated += (sender, e) => parentInvalidatedCallCount++; int parentStyleChangedCallCount = 0; parent.StyleChanged += (sender, e) => parentStyleChangedCallCount++; int parentCreatedCallCount = 0; parent.HandleCreated += (sender, e) => parentCreatedCallCount++; try { control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.Equal(0, layoutCallCount); Assert.Equal(expectedLayoutCallCount, parentLayoutCallCount); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); Assert.True(parent.IsHandleCreated); Assert.Equal(0, parentInvalidatedCallCount); Assert.Equal(0, parentStyleChangedCallCount); Assert.Equal(0, parentCreatedCallCount); // Set same. control.AutoSizeMode = value; Assert.Equal(value, control.AutoSizeMode); Assert.Equal(value, control.GetAutoSizeMode()); Assert.Equal(0, layoutCallCount); Assert.Equal(expectedLayoutCallCount, parentLayoutCallCount); Assert.True(control.IsHandleCreated); Assert.Equal(0, invalidatedCallCount); Assert.Equal(0, styleChangedCallCount); Assert.Equal(0, createdCallCount); Assert.True(parent.IsHandleCreated); Assert.Equal(0, parentInvalidatedCallCount); Assert.Equal(0, parentStyleChangedCallCount); Assert.Equal(0, parentCreatedCallCount); } finally { parent.Layout -= parentHandler; } }
public void Panel_AutoSizeMode_SetInvalid_ThrowsInvalidEnumArgumentException(AutoSizeMode value) { var panel = new Panel(); Assert.Throws <InvalidEnumArgumentException>("value", () => panel.AutoSizeMode = value); }
/// SetAutoSizeMode /// Returns whether or not a control should snap to its smallest size /// or retain its original size and only grow if the preferred size is larger. /// We tried not having GrowOnly as the default, but it becomes difficult /// to design panels or have Buttons maintain their default size of 100,23 internal static void SetAutoSizeMode(IArrangedElement element, AutoSizeMode mode) { BitVector32 state = GetLayoutState(element); state[_autoSizeModeSection] = mode == AutoSizeMode.GrowAndShrink ? 1 : 0; SetLayoutState(element, state); }
public void PublicSetAutoSizeMode (AutoSizeMode mode) { base.SetAutoSizeMode (mode); }
public Control () { if (WindowsFormsSynchronizationContext.AutoInstall) if (!(SynchronizationContext.Current is WindowsFormsSynchronizationContext)) SynchronizationContext.SetSynchronizationContext (new WindowsFormsSynchronizationContext ()); layout_type = LayoutType.Anchor; anchor_style = AnchorStyles.Top | AnchorStyles.Left; is_created = false; is_visible = true; is_captured = false; is_disposed = false; is_enabled = true; is_entered = false; layout_pending = false; is_toplevel = false; causes_validation = true; has_focus = false; layout_suspended = 0; mouse_clicks = 1; tab_index = -1; cursor = null; right_to_left = RightToLeft.Inherit; border_style = BorderStyle.None; background_color = Color.Empty; dist_right = 0; dist_bottom = 0; tab_stop = true; ime_mode = ImeMode.Inherit; use_compatible_text_rendering = true; show_keyboard_cues = false; show_focus_cues = SystemInformation.MenuAccessKeysUnderlined; use_wait_cursor = false; backgroundimage_layout = ImageLayout.Tile; use_compatible_text_rendering = Application.use_compatible_text_rendering; padding = this.DefaultPadding; maximum_size = new Size(); minimum_size = new Size(); margin = this.DefaultMargin; auto_size_mode = AutoSizeMode.GrowOnly; control_style = ControlStyles.UserPaint | ControlStyles.AllPaintingInWmPaint | ControlStyles.Selectable | ControlStyles.StandardClick | ControlStyles.StandardDoubleClick; control_style |= ControlStyles.UseTextForAccessibility; parent = null; background_image = null; text = string.Empty; name = string.Empty; window_target = new ControlWindowTarget(this); window = new ControlNativeWindow(this); child_controls = CreateControlsInstance(); bounds.Size = DefaultSize; client_size = ClientSizeFromSize (bounds.Size); client_rect = new Rectangle (Point.Empty, client_size); explicit_bounds = bounds; }
public void PublicSetAutoSizeMode(AutoSizeMode mode) { base.SetAutoSizeMode(mode); }
protected void SetAutoSizeMode (AutoSizeMode mode) { if (auto_size_mode != mode) { auto_size_mode = mode; PerformLayout (this, "AutoSizeMode"); } }