public static void CreateTutorialArrowWindow(bool upArrow, Point offset, AnchorStyles anchor, Form parentWindow)
 {
     bool doShow = false;
     TutorialArrowWindow window = InterfaceMgr.Instance.getTutorialArrowWindow();
     if (window == null)
     {
         window = new TutorialArrowWindow();
         doShow = true;
     }
     else
     {
         if (parentWindow != lastParent)
         {
             window.Close();
             window = new TutorialArrowWindow();
             doShow = true;
         }
         if (!window.Created || !window.Visible)
         {
             doShow = true;
         }
     }
     if ((window != null) && ((doShow || (offset != window.m_offset)) || (anchor != window.m_anchor)))
     {
         lastParent = parentWindow;
         window.show(upArrow, offset, anchor);
         window.updateLocation(parentWindow);
         window.showTutorialArrowWindow(doShow, parentWindow);
     }
 }
Пример #2
0
        public static IAIPlayer CreateAI(
            IAILogicProvider logicProvider,
            string name,
            int chips,
            Label statusLabel,
            TextBox chipsTextBox,
            AnchorStyles cardHoldersPictureBoxesAnchorStyles,
            int cardHoldersPictureBoxesX,
            int cardHoldersPictureBoxesY)
        {
            IList<PictureBox> cardHolders = GetCardHoldersPictureBoxes(cardHoldersPictureBoxesAnchorStyles,
                cardHoldersPictureBoxesX, cardHoldersPictureBoxesY);

            Panel panel = GetPlayerPanel(cardHolders);

            chipsTextBox.Enabled = false;

            return new AI(
                currentPlayerId,
                name,
                statusLabel,
                chipsTextBox,
                chips,
                cardHolders,
                panel,
                logicProvider);
        }
Пример #3
0
 private void hide_LocationChanged(object sender, EventArgs e)
 {
     if (this.Top <= 0 && this.Left <= 0)
     {
         StopAanhor = AnchorStyles.None;
     }
     else if (this.Top <= 0)
     {
         StopAanhor = AnchorStyles.Top;
     }
     else if (this.Left <= 0)
     {
         StopAanhor = AnchorStyles.Left;
     }
     else if (this.Left >= Screen.PrimaryScreen.Bounds.Width - this.Width)
     {
         StopAanhor = AnchorStyles.Right;
     }
     else if (this.Top >= Screen.PrimaryScreen.Bounds.Height - this.Height)
     {
         StopAanhor = AnchorStyles.Bottom;
     }
     else
     {
         StopAanhor = AnchorStyles.None;
     }
 }
Пример #4
0
        public ToolTab(Tool tool, AnchorStyles anchor, Orientation orientation)
        {
            if(tool == null) throw new ArgumentNullException("tool");

            _tool = tool;
            _anchor = anchor;
            _orientation = orientation;
        }
Пример #5
0
 public void AttachTo(Rectangle r, int padding, AnchorStyles defaultArrowAnchor)
 {
     attachedRect = r;
     attachedTo = null;
     attachedBoundary = null;
     attachedPadding = padding;
     this.defaultArrowAnchor = defaultArrowAnchor;
     OnAttachedLocationChanged();
 }
Пример #6
0
 public IUILayoutParam(AnchorStyles anchorStyle, Padding padding, System.Drawing.Size size,
     int zNear = -1000, int zFar = 1000)
 {
     // TODO: Complete member initialization
     this.Anchor = anchorStyle;
     this.Margin = padding;
     this.Size = size;
     this.zNear = zNear;
     this.zFar = zFar;
 }
Пример #7
0
        private static IList<PictureBox> GetCardHoldersPictureBoxes(
            AnchorStyles cardHoldersPictureBoxesAnchorStyles,
            int cardHoldersPictureBoxesX,
            int cardHoldersPictureBoxesY)
        {
            IList<PictureBox> cardHolders = new List<PictureBox>();
            cardHolders.Add(CreatePictureBox(cardHoldersPictureBoxesAnchorStyles, cardHoldersPictureBoxesX, cardHoldersPictureBoxesY));
            cardHoldersPictureBoxesX += cardHolders.First().Width;
            cardHolders.Add(CreatePictureBox(cardHoldersPictureBoxesAnchorStyles, cardHoldersPictureBoxesX, cardHoldersPictureBoxesY));

            return cardHolders;
        }
        public CustomWitIconButton(Image iconImage, AnchorStyles style, Color color,String toolTipText) {

            Size = new System.Drawing.Size(25, 28);
            Anchor = style;
            FlatStyle = FlatStyle.Flat;
            BackColor = color;
            FlatAppearance.BorderColor = color;
            Image = iconImage;
            ToolTip textMailToolTip = new ToolTip();
            textMailToolTip.SetToolTip(this, toolTipText);

        }
Пример #9
0
 public static void DoIt(QuickGrid grid, 
     PictureBox picture,Control parent,
     AnchorStyles anchor)
 {
     picture.Visible = false;
     grid.Location = picture.Location;
     grid.Visible = true;
     grid.Size = picture.Size;
     grid.Dock = picture.Dock;
     grid.Parent = parent;
     grid.Anchor = anchor;
 }
Пример #10
0
        private int gnzIndex;//对象的Z轴深度

        public Control() {
            //gMouseOn = false;
            base.RefreshAllow = false;

            gVisible = true;
            gbAbsolute = false;
            gAnchor = AnchorStyles.Left | AnchorStyles.Top;
            gnRight = 0;
            gnBottom = 0;
            gbAnchorCache = false;
            gnzIndex = 0;

            base.RefreshAllow = true;
        }
Пример #11
0
 public static DataGridView add_DataGridView(Control cTargetControl,
                                            int iLeft, int iTop, int iWidth, int iHeight,
                                            AnchorStyles asAnchorStyles)
 {
     var dgvDataGridView = new DataGridView();
     dgvDataGridView.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
     dgvDataGridView.Anchor = asAnchorStyles;
     dgvDataGridView.Height = iHeight;
     dgvDataGridView.Width = iWidth;
     dgvDataGridView.Left = iLeft;
     dgvDataGridView.Top = iTop;
     //	dgvDataGridView.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     cTargetControl.Controls.Add(dgvDataGridView);
     return dgvDataGridView;
 }
Пример #12
0
        public Character CreateCharacter(
            string characterType,
            string name,
            int chips,
            Label status,
            TextBox textBox,
            AnchorStyles cardHolderAnchorStyles,
            int pictureBoxX,
            int pictureBoxY)
        {
            IList<PictureBox> cardHolders = new List<PictureBox>();
            cardHolders.Add(CreatePictureBox(cardHolderAnchorStyles, pictureBoxX, pictureBoxY));
            pictureBoxX += cardHolders.First().Width;
            cardHolders.Add(CreatePictureBox(cardHolderAnchorStyles, pictureBoxX, pictureBoxY));

            Panel panel = new Panel();
            panel.Location = new Point(cardHolders.First().Left - 10, cardHolders.Last().Top - 10);
            panel.BackColor = Color.DarkBlue;
            panel.Height = 150;
            panel.Width = 180;
            panel.Visible = false;

            textBox.Enabled = false;
            switch (characterType)
            {
                    
                case "Player":
                    return new Player(
                        characterId,
                        name,
                        status,
                        textBox,
                        chips,
                        cardHolders,
                        panel);
                case "Bot":
                    return new Bot(
                        characterId,
                        name,
                        status,
                        textBox,
                        chips,
                        cardHolders,
                        panel);
                default:
                    throw new PlayerTypeNotImplementedException("");
            }
        }
Пример #13
0
		static AnchorStyles Mirror(AnchorStyles anchor)
		{
			bool right = (anchor & AnchorStyles.Right) == AnchorStyles.Right;
			bool left  = (anchor & AnchorStyles.Left ) == AnchorStyles.Left ;
			if (right) {
				anchor = anchor | AnchorStyles.Left;
			} else {
				anchor = anchor & ~AnchorStyles.Left;
			}
			if (left) {
				anchor = anchor | AnchorStyles.Right;
			} else {
				anchor = anchor & ~AnchorStyles.Right;
			}
			return anchor;
		}
Пример #14
0
        public formAccountTooltip()
        {
            InitializeComponent();

            SetStyle(ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.OptimizedDoubleBuffer, true);
            SetStyle(ControlStyles.UserPaint, true);

            brush = new SolidBrush(Color.Black);
            pen = new Pen(brush);

            this.BackColor = Color.White;
            this.TransparencyKey = Color.Red;

            arrowAnchor = AnchorStyles.Left;
        }
Пример #15
0
        private static PictureBox CreatePictureBox(
            AnchorStyles cardHoldersPictureBoxesAnchorStyles,
            int cardHoldersPictureBoxesX,
            int cardHoldersPictureBoxesY)
        {
            PictureBox cardHolder = new PictureBox();
            cardHolder.SizeMode = PictureBoxSizeMode.StretchImage;
            cardHolder.Height = 130;
            cardHolder.Width = 80;
            cardHolder.Visible = false;
            cardHolder.Name = "pb" + charactersCount++;
            cardHolder.Anchor = cardHoldersPictureBoxesAnchorStyles;
            cardHolder.Location = new Point(cardHoldersPictureBoxesX, cardHoldersPictureBoxesY);

            return cardHolder;
        }
        public FullscreenGraphForm(InteractiveGraphViewer viewer)
        {
            InitializeComponent();
            _OriginalParent = viewer.Parent;
            _OriginalLocation = viewer.Location;
            _OriginalSize = viewer.Size;
            _OriginalDock = viewer.Dock;
            _OriginalAnchors = viewer.Anchor;

            Text = viewer.MaximizedModeTitle;

            viewer.Parent = this;
            viewer.Dock = DockStyle.Fill;
            viewer._Maximized = true;
            _Viewer = viewer;
        }
Пример #17
0
        /// <summary>
        /// Attaches this window to the specified control. This window will move as it does.
        /// </summary>
        /// <param name="control">The control to attach to</param>
        /// <param name="boundary">Optional, this window's arrow will stay within the bounds of the control</param>
        /// <param name="padding">The offset of this window's arrow to the control</param>
        public void AttachTo(Control control, Control boundary, int padding)
        {
            attachedTo = control;
            attachedBoundary = boundary;
            attachedPadding = padding;
            defaultArrowAnchor = AnchorStyles.None;

            //while (control != null)
            //{
            //    control.LocationChanged += control_Changed;
            //    control.SizeChanged += control_Changed;

            //    control = control.Parent;
            //}

            //OnAttachedLocationChanged();
        }
Пример #18
0
 public Cell()
 {
     this.m_anchor = AnchorStyles.Left | AnchorStyles.Top;
     this.m_bVisible = true;
     this.m_sName = "";
     this.Changed = null;
     this.m_anchor = AnchorStyles.Left | AnchorStyles.Top;
     this.m_BackColor = Resco.Controls.AdvancedList.AdvancedList.TransparentColor;
     this.m_ForeColor = Resco.Controls.AdvancedList.AdvancedList.TransparentColor;
     this.m_Bounds = new Rectangle(-1, -1, -1, -1);
     this.m_cellSource = new Resco.Controls.AdvancedList.CellSource();
     this.m_cellSource.Parent = this;
     this.m_Border = BorderType.None;
     this.m_IsAutoHeight = false;
     this.m_CustomizeCell = false;
     this.m_scale = new SizeF(1f, 1f);
 }
Пример #19
0
 public Bot(
     string name,
     int startCard,
     int verticalLocationCoordinate,
     int horizontalLocationCoordinate,
     AnchorStyles verticalLocation = 0,
     AnchorStyles horizontalLocation = 0)
     : base(name)
 {
     this.StartCard = startCard;
     this.VerticalLocationCoordinate = verticalLocationCoordinate;
     this.HorizontalLocationCoordinate = horizontalLocationCoordinate;
     this.HorizontalLocation = horizontalLocation;
     this.VerticalLocation = verticalLocation;
     this.Status = new Label();
     this.TextBoxBotChips = new TextBox();
 }
Пример #20
0
 private static DockMarkerButton GetButton(AnchorStyles side)
 {
     var bounds = new Rectangle(4, 4, 32, 32);
     switch(side)
     {
         case AnchorStyles.Left:
             return new DockMarkerButton(bounds, DockResult.Left);
         case AnchorStyles.Top:
             return new DockMarkerButton(bounds, DockResult.Top);
         case AnchorStyles.Right:
             return new DockMarkerButton(bounds, DockResult.Right);
         case AnchorStyles.Bottom:
             return new DockMarkerButton(bounds, DockResult.Bottom);
         default:
             throw new ArgumentException(
                 "Unknown AnchorStyles value: {0}".UseAsFormat(side),
                 "side");
     }
 }
Пример #21
0
 public Cell(Cell cell)
 {
     this.m_anchor = AnchorStyles.Left | AnchorStyles.Top;
     this.m_bVisible = true;
     this.m_sName = "";
     this.Changed = null;
     this.m_anchor = cell.m_anchor;
     this.m_BackColor = cell.m_BackColor;
     this.m_ForeColor = cell.m_ForeColor;
     this.m_Bounds = cell.m_Bounds;
     this.m_cellSource = cell.m_cellSource.Copy();
     this.m_Border = cell.m_Border;
     this.m_CustomizeCell = cell.m_CustomizeCell;
     this.Name = cell.Name;
     this.m_IsAutoHeight = cell.m_IsAutoHeight;
     this.m_bSelectable = cell.m_bSelectable;
     this.m_bVisible = cell.m_bVisible;
     this.m_scale = cell.m_scale;
 }
Пример #22
0
        public void Attach(Form form, AnchorStyles anchorStyle)
        {
            if (form != null)
            {
                form.Move -= new EventHandler(AttachedFormMove);
                form.Resize -= new EventHandler(AttachedFormResize);
            }

            AttachedToForm = form;
            AttachedStyle = anchorStyle;

            if (form != null)
            {
                form.Move += new EventHandler(AttachedFormMove);
                form.Resize += new EventHandler(AttachedFormResize);

                SyncPosition();
                SyncSize();
            }
        }
Пример #23
0
        /// <summary>Initializes a new instance of the <see cref="ViewTabBase"/> class.</summary>
        /// <param name="view">Represented <see cref="ViewBase"/>.</param>
        /// <param name="anchor">Tab anchor.</param>
        protected ViewTabBase(ViewBase view, AnchorStyles anchor)
        {
            Verify.Argument.IsNotNull(view, "view");

            switch(anchor)
            {
                case AnchorStyles.Left:
                case AnchorStyles.Right:
                    _orientation = Orientation.Vertical;
                    break;
                case AnchorStyles.Top:
                case AnchorStyles.Bottom:
                    _orientation = Orientation.Horizontal;
                    break;
                default:
                    throw new ArgumentException("Invalid anchor value.", "anchor");
            }
            _anchor = anchor;
            _view = view;
        }
Пример #24
0
        public AutoGrow(Control container, AnchorStyles direction, bool allowShrink)
        {
            Debug.Assert(container.Dock != DockStyle.Fill, "Can't autogrow a docked container");

            switch (direction)
            {
                case AnchorStyles.None:
                case AnchorStyles.Right:
                case AnchorStyles.Bottom:
                case AnchorStyles.Right | AnchorStyles.Bottom:
                    break;
                default:
                    throw new ArgumentException("Only combinations of Right and Bottom are allowed");
            }

            _direction = direction;
            _container = container;
            Point maxChildPoint = GetMaxChildPoint(container);
            _margin = new Size(container.Width - maxChildPoint.X, container.Height - maxChildPoint.Y);
            _allowShrink = allowShrink;
        }
		static string GetAnchorStyleAsString(AnchorStyles anchorStyles)
		{
			if (anchorStyles == AnchorStyles.None) {
				return typeof(AnchorStyles).FullName + "." + AnchorStyles.None;
			}
			
			StringBuilder text = new StringBuilder();
			bool firstStyle = true;
			foreach (AnchorStyles style in AnchorStyles.GetValues(typeof(AnchorStyles))) {
				if (style != AnchorStyles.None) {
					if ((anchorStyles & style) == style) {
						if (firstStyle) {
							firstStyle = false;
						} else {
							text.Append(" | ");
						}
						text.Append(typeof(AnchorStyles).FullName);
						text.Append('.');
						text.Append(style);
					}
				}
			}
			return text.ToString();
		}
Пример #26
0
        void LayoutAnchoredChildren(Control parent, Control[] controls)
        {
            Rectangle space = parent.ClientRectangle;

            for (int i = 0; i < controls.Length; i++)
            {
                int left;
                int top;
                int width;
                int height;

                Control child = controls[i];

                if (!child.VisibleInternal ||
                    child.ControlLayoutType == Control.LayoutType.Dock)
                {
                    continue;
                }

                AnchorStyles anchor = child.Anchor;

                left = child.Left;
                top  = child.Top;

                width  = child.Width;
                height = child.Height;

                if ((anchor & AnchorStyles.Right) != 0)
                {
                    if ((anchor & AnchorStyles.Left) != 0)
                    {
                        width = space.Width - child.dist_right - left;
                    }
                    else
                    {
                        left = space.Width - child.dist_right - width;
                    }
                }
                else if ((anchor & AnchorStyles.Left) == 0)
                {
                    // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
                    // This calculates from scratch every time:
                    left             = left + (space.Width - (left + width + child.dist_right)) / 2;
                    child.dist_right = space.Width - (left + width);
                }

                if ((anchor & AnchorStyles.Bottom) != 0)
                {
                    if ((anchor & AnchorStyles.Top) != 0)
                    {
                        height = space.Height - child.dist_bottom - top;
                    }
                    else
                    {
                        top = space.Height - child.dist_bottom - height;
                    }
                }
                else if ((anchor & AnchorStyles.Top) == 0)
                {
                    // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
                    // This calculates from scratch every time:
                    top = top + (space.Height - (top + height + child.dist_bottom)) / 2;
                    child.dist_bottom = space.Height - (top + height);
                }

                // Sanity
                if (width < 0)
                {
                    width = 0;
                }

                if (height < 0)
                {
                    height = 0;
                }

                child.SetBoundsInternal(left, top, width, height, BoundsSpecified.None);
            }
        }
Пример #27
0
        // <summary>
        ///  LayoutRow and MeasureRow both forward to this method. The measureOnly flag
        ///  determines which behavior we get.
        /// </summary>
        private Size TryCalculatePreferredSizeRow(ContainerProxy containerProxy, ElementProxy elementProxy, int startIndex, int endIndex, Rectangle rowBounds, out int breakIndex, bool measureOnly)
        {
            Debug.Assert(startIndex < endIndex, "Loop should be in forward Z-order.");
            Point location     = rowBounds.Location;
            Size  rowSize      = Size.Empty;
            int   laidOutItems = 0;

            breakIndex = startIndex;

            bool wrapContents    = GetWrapContents(containerProxy.Container);
            bool breakOnNextItem = false;

            ArrangedElementCollection collection = containerProxy.Container.Children;

            for (int i = startIndex; i < endIndex; i++, breakIndex++)
            {
                elementProxy.Element = collection[i];
                if (!elementProxy.ParticipatesInLayout)
                {
                    continue;
                }

                // Figure out how much space this element is going to need (requiredSize)
                Size prefSize;
                if (elementProxy.AutoSize)
                {
                    Size elementConstraints = new Size(int.MaxValue, rowBounds.Height - elementProxy.Margin.Size.Height);
                    if (i == startIndex)
                    {
                        // If the element is the first in the row, attempt to pack it to the row width. (If its not 1st, it will wrap
                        // to the first on the next row if its too long and then be packed if needed by the next call to TryCalculatePreferredSizeRow).
                        elementConstraints.Width = rowBounds.Width - rowSize.Width - elementProxy.Margin.Size.Width;
                    }

                    // Make sure that subtracting the margins does not cause width/height to be <= 0, or we will
                    // size as if we had infinite space when in fact we are trying to be as small as possible.
                    elementConstraints = LayoutUtils.UnionSizes(new Size(1, 1), elementConstraints);
                    prefSize           = elementProxy.GetPreferredSize(elementConstraints);
                }
                else
                {
                    // If autosizing is turned off, we just use the element's current size as its preferred size.
                    prefSize = elementProxy.SpecifiedSize;

                    // except if it is stretching - then ignore the affect of the height dimension.
                    if (elementProxy.Stretches)
                    {
                        prefSize.Height = 0;
                    }

                    // Enforce MinimumSize
                    if (prefSize.Height < elementProxy.MinimumSize.Height)
                    {
                        prefSize.Height = elementProxy.MinimumSize.Height;
                    }
                }

                Size requiredSize = prefSize + elementProxy.Margin.Size;

                // Position the element (if applicable).
                if (!measureOnly)
                {
                    // If measureOnly = false, rowBounds.Height = measured row hieght
                    // (otherwise its the remaining displayRect of the container)

                    Rectangle cellBounds = new Rectangle(location, new Size(requiredSize.Width, rowBounds.Height));

                    // We laid out the rows with the elementProxy's margins included.
                    // We now deflate the rect to get the actual elementProxy bounds.
                    cellBounds = LayoutUtils.DeflateRect(cellBounds, elementProxy.Margin);

                    AnchorStyles anchorStyles = elementProxy.AnchorStyles;
                    containerProxy.Bounds = LayoutUtils.AlignAndStretch(prefSize, cellBounds, anchorStyles);
                }

                // Keep track of how much space is being used in this row
                location.X += requiredSize.Width;
                if (laidOutItems > 0)
                {
                    // If control does not fit on this row, exclude it from row and stop now.
                    //   Exception: If row is empty, allow this control to fit on it. So controls
                    //   that exceed the maximum row width will end up occupying their own rows.
                    if (location.X > rowBounds.Right)
                    {
                        break;
                    }
                }

                // Control fits on this row, so update the row size.
                //   rowSize.Width != location.X because with a scrollable control
                //   we could have started with a location like -100.
                rowSize.Width  = location.X - rowBounds.X;
                rowSize.Height = Math.Max(rowSize.Height, requiredSize.Height);

                // check for line breaks.
                if (wrapContents)
                {
                    if (breakOnNextItem)
                    {
                        break;
                    }
                    else if (i + 1 < endIndex && CommonProperties.GetFlowBreak(elementProxy.Element))
                    {
                        if (laidOutItems == 0)
                        {
                            breakOnNextItem = true;
                        }
                        else
                        {
                            breakIndex++;
                            break;
                        }
                    }
                }

                laidOutItems++;
            }

            return(rowSize);
        }
		protected ToolStripItem (string text, Image image, EventHandler onClick, string name)
		{
			this.alignment = ToolStripItemAlignment.Left;
			this.anchor = AnchorStyles.Left | AnchorStyles.Top;
			this.auto_size = true;
			this.auto_tool_tip = this.DefaultAutoToolTip;
			this.available = true;
			this.back_color = Color.Empty;
			this.background_image_layout = ImageLayout.Tile;
			this.can_select = true;
			this.display_style = this.DefaultDisplayStyle;
			this.dock = DockStyle.None;
			this.enabled = true;
			this.fore_color = Color.Empty;
			this.image = image;
			this.image_align = ContentAlignment.MiddleCenter;
			this.image_index = -1;
			this.image_key = string.Empty;
			this.image_scaling = ToolStripItemImageScaling.SizeToFit;
			this.image_transparent_color = Color.Empty;
			this.margin = this.DefaultMargin;
			this.merge_action = MergeAction.Append;
			this.merge_index = -1;
			this.name = name;
			this.overflow = ToolStripItemOverflow.AsNeeded;
			this.padding = this.DefaultPadding;
			this.placement = ToolStripItemPlacement.None;
			this.right_to_left = RightToLeft.Inherit;
			this.bounds.Size = this.DefaultSize;
			this.text = text;
			this.text_align = ContentAlignment.MiddleCenter;
			this.text_direction = DefaultTextDirection;
			this.text_image_relation = TextImageRelation.ImageBeforeText;
			this.visible = true;

			this.Click += onClick;
			OnLayout (new LayoutEventArgs (null, string.Empty));
		}
Пример #29
0
 public void DockSide(AnchorStyles side, ViewBase view, bool autoHide)
 {
     DockSide(side, new ViewHost(this, false, false, new[] { view }), autoHide);
 }
Пример #30
0
 internal void DockSide(AnchorStyles side, ViewHost host, bool autoHide)
 {
     host.DockToSide(RootControl, side);
 }
        public LButton(
            Control parentpal,
            int lineint,
            string text,
            Font font,
            Size size,
            Point point,
            Color linecolor,
            Color linelight,
            Color backcolor,
            Color backlight,
            Color forecolor,
            Color forelight,
            AnchorStyles anchorstyle
            )
        {
            Linecolor = linecolor;
            Linelight = linelight;
            Backcolor = backcolor;
            Backlight = backlight;
            Forecolor = forecolor;
            Forelight = forelight;

            var panelSec = new HPanel
                {
                    Size = size,
                    Location = point,
                    Anchor = anchorstyle,
                    BackColor = linecolor,
                };

            Text = text;
            Font = font;
            TextAlign = ContentAlignment.MiddleCenter;
            Size = new Size(panelSec.Size.Width - 2*lineint, panelSec.Size.Height - 2*lineint);
            Location = new Point(lineint, lineint);
            ForeColor = Forecolor;
            BackColor = Backcolor;
            Anchor = AnchorStyles.Top;
            Cursor = Cursors.Hand;

            panelSec.Controls.Add(this);
            parentpal.Controls.Add(panelSec);

            MouseUp += LButton_MouseUp;
            MouseDown += LButton_MouseDown;
            MouseHover += LButton_MouseHover;
            MouseLeave += LButton_MouseLeave;
        }
Пример #32
0
        public void UpdateView()
        {
            this.ViewUpdating = true;

            //同步特有属性
            FormElementDataListEntityDev formElement = (FormElementDataListEntityDev)_formElement;

            PropertyDescriptor pds;

            #region 主体部分

            AnchorStyles anchorStyles = new AnchorStyles();

            //处理边缘锚定
            //先清除所有方向描定,.net默认左上角锚定
            anchorStyles = anchorStyles & (AnchorStyles)AnchorStyles.Top;
            anchorStyles = anchorStyles & (AnchorStyles)AnchorStyles.Right;
            anchorStyles = anchorStyles & (AnchorStyles)AnchorStyles.Bottom;
            anchorStyles = anchorStyles & (AnchorStyles)AnchorStyles.Left;

            if (formElement.Anchor.Top)
            {
                anchorStyles = anchorStyles | (AnchorStyles)AnchorStyles.Top;
            }
            if (formElement.Anchor.Right)
            {
                anchorStyles = anchorStyles | (AnchorStyles)AnchorStyles.Right;
            }
            if (formElement.Anchor.Bottom)
            {
                anchorStyles = anchorStyles | (AnchorStyles)AnchorStyles.Bottom;
            }
            if (formElement.Anchor.Left)
            {
                anchorStyles = anchorStyles | (AnchorStyles)AnchorStyles.Left;
            }

            ShellControlHelper.SetProperty(this, "Anchor", anchorStyles);

            ShellControlHelper.SetProperty(this, "Text", formElement.Text);
            ShellControlHelper.SetProperty(this, "Size", formElement.Size);
            ShellControlHelper.SetProperty(this, "Location", formElement.Location);
            ShellControlHelper.SetProperty(this, "Text", formElement.Text);
            ShellControlHelper.SetProperty(this, "ForeColor", formElement.ForeColor);
            ShellControlHelper.SetProperty(this, "Visible", formElement.Visible);
            ShellControlHelper.SetProperty(this, "Enabled", formElement.Enabled);
            //ShellControlHelper.SetProperty(this, "NavigationLocation", formElement.NavigationLocation);
            //ShellControlHelper.SetProperty(this, "Pagination", formElement.Pagination);
            //ShellControlHelper.SetProperty(this, "ShowItemCount", formElement.ShowItemCount);
            //ShellControlHelper.SetProperty(this, "ShowPageCount", formElement.ShowPageCount);
            //ShellControlHelper.SetProperty(this, "ShowPageHomeEnd", formElement.ShowPageHomeEnd);
            ShellControlHelper.SetProperty(this, "TabIndex", formElement.TabIndex);

            #endregion

            #region DataGridView部分

            PropertyDescriptorCollection pdcDataGridView = TypeDescriptor.GetProperties(this);

            pds = pdcDataGridView.Find("BackgroundColor", false);
            if (pds != null)
            {
                //DataGridView.BackgroundColor不支持Color.Empty
                if (formElement.BackColor == Color.Empty)
                {
                    formElement.BackColorValue = "2.Window";
                }

                if (!pds.GetValue(this).Equals(formElement.BackColor))
                {
                    pds.SetValue(this, formElement.BackColor);
                }
            }

            #region 列同步不能,原因不明

            //列

            /*
             * DataGridViewColumnCollection dataGridViewColumnCollection = new DataGridViewColumnCollection(this.DataGridView);
             * foreach (FormElementDataColumnEntityDev column in formElement.DataColumns)
             * {
             *  dataGridViewColumnCollection.Add(new DataGridViewTextBoxColumnDev(column));
             * }
             *
             * pds = pdcDataGridView.Find("Columns", false);
             * if (pds != null)
             * {
             *  pds.SetValue(this.DataGridView, dataGridViewColumnCollection);
             * }
             */

            #endregion
            this.Columns.Clear();
            foreach (FormElementDataListTextBoxColumnEntityDev column in formElement.DataColumns)
            {
                //编辑数据列之后,列对象的DataList属性会为空
                //在这里将DataList属性再次绑定上,放在这里也是为了避免其它类似潜在的问题
                column.DataList = (FormElementDataListEntityDev)this._entity;

                // Debug.Assert(column.DataList != null, "FormElementDataColumnEntityDev 对象的 DataList 属性为 null");

                this.Columns.Add(DataGridViewColumnFactory.GetDataGridViewColumn(column));
            }

            #endregion

            this.ViewUpdating = false;
        }
Пример #33
0
        static void LayoutAnchoredChildren(IArrangedElement parent, IList controls)
        {
            Rectangle space = parent.DisplayRectangle;

            foreach (IArrangedElement child in controls)
            {
                if (!child.Visible || child.Dock != DockStyle.None)
                {
                    continue;
                }

                AnchorStyles anchor = child.Anchor;
                Rectangle    bounds = child.Bounds;
                int          left   = bounds.Left;
                int          top    = bounds.Top;
                int          width  = bounds.Width;
                int          height = bounds.Height;

                if ((anchor & AnchorStyles.Right) != 0)
                {
                    if ((anchor & AnchorStyles.Left) != 0)
                    {
                        width = space.Right - child.DistanceRight - left;
                    }
                    else
                    {
                        left = space.Right - child.DistanceRight - width;
                    }
                }
                else if ((anchor & AnchorStyles.Left) == 0)
                {
                    // left+=diff_width/2 will introduce rounding errors (diff_width removed from svn after r51780)
                    // This calculates from scratch every time:
                    left += (space.Width - (left + width + child.DistanceRight)) / 2;
                    child.DistanceRight = space.Width - (left + width);
                }

                if ((anchor & AnchorStyles.Bottom) != 0)
                {
                    if ((anchor & AnchorStyles.Top) != 0)
                    {
                        height = space.Bottom - child.DistanceBottom - top;
                    }
                    else
                    {
                        top = space.Bottom - child.DistanceBottom - height;
                    }
                }
                else if ((anchor & AnchorStyles.Top) == 0)
                {
                    // top += diff_height/2 will introduce rounding errors (diff_height removed from after r51780)
                    // This calculates from scratch every time:
                    top += (space.Height - (top + height + child.DistanceBottom)) / 2;
                    child.DistanceBottom = space.Height - (top + height);
                }

                // Sanity
                if (width < 0)
                {
                    width = 0;
                }
                if (height < 0)
                {
                    height = 0;
                }

                if (child.AutoSize)
                {
                    Size proposed_size = Size.Empty;
                    if ((anchor & (AnchorStyles.Left | AnchorStyles.Right)) == (AnchorStyles.Left | AnchorStyles.Right))
                    {
                        proposed_size.Width = width;
                    }
                    if ((anchor & (AnchorStyles.Top | AnchorStyles.Bottom)) == (AnchorStyles.Top | AnchorStyles.Bottom))
                    {
                        proposed_size.Height = height;
                    }

                    Size preferred_size = GetPreferredControlSize(child, proposed_size);

                    if ((anchor & (AnchorStyles.Left | AnchorStyles.Right)) != AnchorStyles.Right)
                    {
                        child.DistanceRight += width - preferred_size.Width;
                    }
                    else
                    {
                        left += width - preferred_size.Width;
                    }
                    if ((anchor & (AnchorStyles.Top | AnchorStyles.Bottom)) != AnchorStyles.Bottom)
                    {
                        child.DistanceBottom += height - preferred_size.Height;
                    }
                    else
                    {
                        top += height - preferred_size.Height;
                    }

                    child.SetBounds(left, top, preferred_size.Width, preferred_size.Height, BoundsSpecified.None);
                }
                else
                {
                    child.SetBounds(left, top, width, height, BoundsSpecified.None);
                }
            }
        }
Пример #34
0
        public static Image CreateTornEdge(Image sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange, AnchorStyles sides)
        {
            Image result = sourceImage.CreateEmptyBitmap();

            using (GraphicsPath path = new GraphicsPath())
            {
                Random random = new Random();
                int horizontalRegions = sourceImage.Width / horizontalToothRange;
                int verticalRegions = sourceImage.Height / verticalToothRange;

                Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
                Point newEndingPoint;

                if (sides.HasFlag(AnchorStyles.Top))
                {
                    for (int i = 0; i < horizontalRegions; i++)
                    {
                        int x = previousEndingPoint.X + horizontalToothRange;
                        int y = random.Next(1, toothHeight);
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(0, 0);
                    newEndingPoint = new Point(sourceImage.Width, 0);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Right))
                {
                    for (int i = 0; i < verticalRegions; i++)
                    {
                        int x = sourceImage.Width - random.Next(1, toothHeight);
                        int y = previousEndingPoint.Y + verticalToothRange;
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(sourceImage.Width, 0);
                    newEndingPoint = new Point(sourceImage.Width, sourceImage.Height);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Bottom))
                {
                    for (int i = 0; i < horizontalRegions; i++)
                    {
                        int x = previousEndingPoint.X - horizontalToothRange;
                        int y = sourceImage.Height - random.Next(1, toothHeight);
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(sourceImage.Width, sourceImage.Height);
                    newEndingPoint = new Point(0, sourceImage.Height);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Left))
                {
                    for (int i = 0; i < verticalRegions; i++)
                    {
                        int x = random.Next(1, toothHeight);
                        int y = previousEndingPoint.Y - verticalToothRange;
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(0, sourceImage.Height);
                    newEndingPoint = new Point(0, 0);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                path.CloseFigure();

                using (Graphics graphics = Graphics.FromImage(result))
                {
                    graphics.SmoothingMode = SmoothingMode.HighQuality;
                    graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;

                    // Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing
                    using (Brush brush = new TextureBrush(sourceImage))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
            }

            return result;
        }
        // Generates a Form Control of specific type T with the given parameters; makes instantiating new Controls easier to read
        public static GUIControlWrapper <T> CreateControl <T>(int width, int height, int xPosition, int yPosition, AnchorStyles anchor = 0, int fontSize = 9) where T : System.Windows.Forms.Control, new()
        {
            var newControl = new GUIControlWrapper <T>(width, height);

            newControl.SetPosition(xPosition, yPosition);

            newControl.SetAnchor(anchor);

            newControl.control.Font = newControl.ConstructFont(fontSize);

            return(newControl);
        }
Пример #36
0
        private static Rectangle GetAnchorDestination(IArrangedElement element, Rectangle displayRect, bool measureOnly)
        {
            // Container can not be null since we AnchorControls takes a non-null container.
            //
            // NB: DO NOT convert the following into Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "...")
            // because it WILL execute GetCachedBounds(element).ToString() calls even if CompModSwitches.RichLayout.TraceInfo=false
            // This in turn will lead to a cascade of native calls and callbacks
            if (CompModSwitches.RichLayout.TraceInfo)
            {
                Debug.WriteLine($"\t\t'{element}' is anchored at {GetCachedBounds(element).ToString()}");
            }

            AnchorInfo layout = GetAnchorInfo(element);

            int left   = layout.Left + displayRect.X;
            int top    = layout.Top + displayRect.Y;
            int right  = layout.Right + displayRect.X;
            int bottom = layout.Bottom + displayRect.Y;

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...anchor dim (l,t,r,b) {"
                              + (left)
                              + ", " + (top)
                              + ", " + (right)
                              + ", " + (bottom)
                              + "}");

            AnchorStyles anchor = GetAnchor(element);

            if (IsAnchored(anchor, AnchorStyles.Right))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting right");
                right += displayRect.Width;

                if (!IsAnchored(anchor, AnchorStyles.Left))
                {
                    Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting left");
                    left += displayRect.Width;
                }
            }
            else if (!IsAnchored(anchor, AnchorStyles.Left))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting left & right");
                right += (displayRect.Width / 2);
                left  += (displayRect.Width / 2);
            }

            if (IsAnchored(anchor, AnchorStyles.Bottom))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting bottom");
                bottom += displayRect.Height;

                if (!IsAnchored(anchor, AnchorStyles.Top))
                {
                    Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting top");
                    top += displayRect.Height;
                }
            }
            else if (!IsAnchored(anchor, AnchorStyles.Top))
            {
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...adjusting top & bottom");
                bottom += (displayRect.Height / 2);
                top    += (displayRect.Height / 2);
            }

            if (!measureOnly)
            {
                // the size is actually zero, set the width and heights appropriately.
                if (right < left)
                {
                    right = left;
                }

                if (bottom < top)
                {
                    bottom = top;
                }
            }
            else
            {
                Rectangle cachedBounds = GetCachedBounds(element);
                // in this scenario we've likely been passed a 0 sized display rectangle to determine our height.
                // we will need to translate the right and bottom edges as necessary to the positive plane.

                // right < left means the control is anchored both left and right.
                // cachedBounds != element.Bounds means  the element's size has changed
                // any, all, or none of these can be true.
                if (right < left || cachedBounds.Width != element.Bounds.Width || cachedBounds.X != element.Bounds.X)
                {
                    if (cachedBounds != element.Bounds)
                    {
                        left = Math.Max(Math.Abs(left), Math.Abs(cachedBounds.Left));
                    }

                    right = left + Math.Max(element.Bounds.Width, cachedBounds.Width) + Math.Abs(right);
                }
                else
                {
                    left  = left > 0 ? left : element.Bounds.Left;
                    right = right > 0 ? right : element.Bounds.Right + Math.Abs(right);
                }

                // bottom < top means the control is anchored both top and bottom.
                // cachedBounds != element.Bounds means  the element's size has changed
                // any, all, or none of these can be true.
                if (bottom < top || cachedBounds.Height != element.Bounds.Height || cachedBounds.Y != element.Bounds.Y)
                {
                    if (cachedBounds != element.Bounds)
                    {
                        top = Math.Max(Math.Abs(top), Math.Abs(cachedBounds.Top));
                    }

                    bottom = top + Math.Max(element.Bounds.Height, cachedBounds.Height) + Math.Abs(bottom);
                }
                else
                {
                    top    = top > 0 ? top : element.Bounds.Top;
                    bottom = bottom > 0 ? bottom : element.Bounds.Bottom + Math.Abs(bottom);
                }
            }

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "\t\t...new anchor dim (l,t,r,b) {"
                              + (left)
                              + ", " + (top)
                              + ", " + (right)
                              + ", " + (bottom)
                              + "}");

            return(new Rectangle(left, top, right - left, bottom - top));
        }
Пример #37
0
        /// <summary>
        /// 锚定内容矩形到容器矩形
        /// </summary>
        /// <param name="containerBounds">容器矩形</param>
        /// <param name="contentBounds">内容矩形</param>
        /// <param name="anchor">锚定方式</param>
        /// <returns>新矩形</returns>
        private static Rectangle SubstituteSpecifiedBounds(Rectangle containerBounds, Rectangle contentBounds, AnchorStyles anchor)
        {
            int left   = ((anchor & AnchorStyles.Left) != AnchorStyles.None) ? contentBounds.Left : containerBounds.Left;
            int top    = ((anchor & AnchorStyles.Top) != AnchorStyles.None) ? contentBounds.Top : containerBounds.Top;
            int right  = ((anchor & AnchorStyles.Right) != AnchorStyles.None) ? contentBounds.Right : containerBounds.Right;
            int bottom = ((anchor & AnchorStyles.Bottom) != AnchorStyles.None) ? contentBounds.Bottom : containerBounds.Bottom;

            return(Rectangle.FromLTRB(left, top, right, bottom));
        }
Пример #38
0
        private static void UpdateAnchorInfo(IArrangedElement element)
        {
            Debug.Assert(!HasCachedBounds(element.Container), "Do not call this method with an active cached bounds list.");

            AnchorInfo anchorInfo = GetAnchorInfo(element);

            if (anchorInfo is null)
            {
                anchorInfo = new AnchorInfo();
                SetAnchorInfo(element, anchorInfo);
            }

            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Update anchor info");
            Debug.Indent();
            Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, element.Container is null ? "No parent" : "Parent");

            if (CommonProperties.GetNeedsAnchorLayout(element) && element.Container is not null)
            {
                Rectangle  bounds        = GetCachedBounds(element);
                AnchorInfo oldAnchorInfo = new AnchorInfo
                {
                    Left   = anchorInfo.Left,
                    Top    = anchorInfo.Top,
                    Right  = anchorInfo.Right,
                    Bottom = anchorInfo.Bottom
                };

                anchorInfo.Left   = element.Bounds.Left;
                anchorInfo.Top    = element.Bounds.Top;
                anchorInfo.Right  = element.Bounds.Right;
                anchorInfo.Bottom = element.Bounds.Bottom;

                Rectangle parentDisplayRect = element.Container.DisplayRectangle;
                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "Parent displayRectangle" + parentDisplayRect);
                int parentWidth  = parentDisplayRect.Width;
                int parentHeight = parentDisplayRect.Height;

                // The anchor is relative to the parent DisplayRectangle, so offset the anchor
                // by the DisplayRect origin
                anchorInfo.Left   -= parentDisplayRect.X;
                anchorInfo.Top    -= parentDisplayRect.Y;
                anchorInfo.Right  -= parentDisplayRect.X;
                anchorInfo.Bottom -= parentDisplayRect.Y;

                AnchorStyles anchor = GetAnchor(element);
                if (IsAnchored(anchor, AnchorStyles.Right))
                {
                    if (DpiHelper.IsScalingRequirementMet && (anchorInfo.Right - parentWidth > 0) && (oldAnchorInfo.Right < 0))
                    {
                        // Parent was resized to fit its parent, or screen, we need to reuse old anchor info to prevent losing control beyond right edge.
                        anchorInfo.Right = oldAnchorInfo.Right;
                        if (!IsAnchored(anchor, AnchorStyles.Left))
                        {
                            // Control might have been resized, update Left anchor.
                            anchorInfo.Left = oldAnchorInfo.Right - bounds.Width;
                        }
                    }
                    else
                    {
                        anchorInfo.Right -= parentWidth;

                        if (!IsAnchored(anchor, AnchorStyles.Left))
                        {
                            anchorInfo.Left -= parentWidth;
                        }
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Left))
                {
                    anchorInfo.Right -= (parentWidth / 2);
                    anchorInfo.Left  -= (parentWidth / 2);
                }

                if (IsAnchored(anchor, AnchorStyles.Bottom))
                {
                    if (DpiHelper.IsScalingRequirementMet && (anchorInfo.Bottom - parentHeight > 0) && (oldAnchorInfo.Bottom < 0))
                    {
                        // Parent was resized to fit its parent, or screen, we need to reuse old anchor info to prevent losing control beyond bottom edge.
                        anchorInfo.Bottom = oldAnchorInfo.Bottom;

                        if (!IsAnchored(anchor, AnchorStyles.Top))
                        {
                            // Control might have been resized, update Top anchor.
                            anchorInfo.Top = oldAnchorInfo.Bottom - bounds.Height;
                        }
                    }
                    else
                    {
                        anchorInfo.Bottom -= parentHeight;

                        if (!IsAnchored(anchor, AnchorStyles.Top))
                        {
                            anchorInfo.Top -= parentHeight;
                        }
                    }
                }
                else if (!IsAnchored(anchor, AnchorStyles.Top))
                {
                    anchorInfo.Bottom -= (parentHeight / 2);
                    anchorInfo.Top    -= (parentHeight / 2);
                }

                Debug.WriteLineIf(CompModSwitches.RichLayout.TraceInfo, "anchor info (l,t,r,b): (" + anchorInfo.Left + ", " + anchorInfo.Top + ", " + anchorInfo.Right + ", " + anchorInfo.Bottom + ")");
            }

            Debug.Unindent();
        }
Пример #39
0
        public static Image CreateTornEdge(Image sourceImage, int toothHeight, int horizontalToothRange, int verticalToothRange, AnchorStyles sides)
        {
            Image result = sourceImage.CreateEmptyBitmap();

            using (GraphicsPath path = new GraphicsPath())
            {
                Random random            = new Random();
                int    horizontalRegions = sourceImage.Width / horizontalToothRange;
                int    verticalRegions   = sourceImage.Height / verticalToothRange;

                Point previousEndingPoint = new Point(horizontalToothRange, random.Next(1, toothHeight));
                Point newEndingPoint;

                if (sides.HasFlag(AnchorStyles.Top))
                {
                    for (int i = 0; i < horizontalRegions; i++)
                    {
                        int x = previousEndingPoint.X + horizontalToothRange;
                        int y = random.Next(1, toothHeight);
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(0, 0);
                    newEndingPoint      = new Point(sourceImage.Width, 0);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Right))
                {
                    for (int i = 0; i < verticalRegions; i++)
                    {
                        int x = sourceImage.Width - random.Next(1, toothHeight);
                        int y = previousEndingPoint.Y + verticalToothRange;
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(sourceImage.Width, 0);
                    newEndingPoint      = new Point(sourceImage.Width, sourceImage.Height);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Bottom))
                {
                    for (int i = 0; i < horizontalRegions; i++)
                    {
                        int x = previousEndingPoint.X - horizontalToothRange;
                        int y = sourceImage.Height - random.Next(1, toothHeight);
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(sourceImage.Width, sourceImage.Height);
                    newEndingPoint      = new Point(0, sourceImage.Height);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                if (sides.HasFlag(AnchorStyles.Left))
                {
                    for (int i = 0; i < verticalRegions; i++)
                    {
                        int x = random.Next(1, toothHeight);
                        int y = previousEndingPoint.Y - verticalToothRange;
                        newEndingPoint = new Point(x, y);
                        path.AddLine(previousEndingPoint, newEndingPoint);
                        previousEndingPoint = newEndingPoint;
                    }
                }
                else
                {
                    previousEndingPoint = new Point(0, sourceImage.Height);
                    newEndingPoint      = new Point(0, 0);
                    path.AddLine(previousEndingPoint, newEndingPoint);
                    previousEndingPoint = newEndingPoint;
                }

                path.CloseFigure();

                using (Graphics graphics = Graphics.FromImage(result))
                {
                    graphics.SmoothingMode      = SmoothingMode.HighQuality;
                    graphics.PixelOffsetMode    = PixelOffsetMode.HighQuality;
                    graphics.CompositingQuality = CompositingQuality.HighQuality;
                    graphics.InterpolationMode  = InterpolationMode.HighQualityBicubic;

                    // Draw the created figure with the original image by using a TextureBrush so we have anti-aliasing
                    using (Brush brush = new TextureBrush(sourceImage))
                    {
                        graphics.FillPath(brush, path);
                    }
                }
            }

            return(result);
        }
Пример #40
0
        public static Rectangle CleverConstrain(Rectangle initialBounds, double?aspectRatio, AnchorStyles anchor, Point newLoc)
        {
            if (aspectRatio == null)
            {
                aspectRatio = initialBounds.Width / (double)initialBounds.Height;
            }

            bool up   = AnchorStyles.Bottom == (anchor & AnchorStyles.Bottom);
            bool left = AnchorStyles.Right == (anchor & AnchorStyles.Right);

            PointF origin = new PointF(
                initialBounds.Left + (left ? initialBounds.Width : 0),
                initialBounds.Top + (up ? initialBounds.Height : 0));

            double desiredAngle = Math.Atan2(
                1d * (up ? -1 : 1),
                1d * aspectRatio.Value * (left ? -1 : 1));

            double actualAngle = Math.Atan2(
                newLoc.Y - origin.Y,
                newLoc.X - origin.X);

            double angleDiff = Math.Abs(actualAngle - desiredAngle);

            if (angleDiff >= Math.PI / 2) // >=90 degrees--too much angle!
            {
                return(DoResize(initialBounds, anchor, new Point((int)origin.X, (int)origin.Y)));
            }

            double distance = Distance(origin, newLoc);

            double resizeMagnitude = Math.Cos(angleDiff) * distance;
            double xMagnitude      = resizeMagnitude * Math.Cos(desiredAngle);
            double yMagnitude      = resizeMagnitude * Math.Sin(desiredAngle);

            newLoc.X = Round(origin.X + xMagnitude);
            newLoc.Y = Round(origin.Y + yMagnitude);

            return(DoResize(initialBounds, anchor, newLoc));
        }
 public void SetAnchor(AnchorStyles anchor) => control.Anchor = anchor;
Пример #42
0
        private static Rectangle SubstituteSpecifiedBounds(Rectangle originalBounds, Rectangle substitutionBounds, AnchorStyles specified)
        {
            int left   = (specified & AnchorStyles.Left) != 0 ? substitutionBounds.Left : originalBounds.Left;
            int top    = (specified & AnchorStyles.Top) != 0 ? substitutionBounds.Top : originalBounds.Top;
            int right  = (specified & AnchorStyles.Right) != 0 ? substitutionBounds.Right : originalBounds.Right;
            int bottom = (specified & AnchorStyles.Bottom) != 0 ? substitutionBounds.Bottom : originalBounds.Bottom;

            return(Rectangle.FromLTRB(left, top, right, bottom));
        }
        public InputSearch(
            Control parentpal,
            int lineint,
            int lineflo,
            string predesc,
            string preword,
            Font descfont,
            Size descsize,
            Font font,
            Size size,
            Point point,
            Color defrcolor,
            Color debkcolor,
            Color linecolor,
            Color linelight,
            Color backcolor,
            Color backlight,
            Color forecolor,
            Color forelight,
            MouseEventHandler searchEnter,
            KeyEventHandler searchEnterKey,
            AnchorStyles anchorstyle
            )
        {
            Linecolor = linecolor;
            Linelight = linelight;
            Backcolor = backcolor;
            Backlight = backlight;
            Forecolor = forecolor;
            Forelight = forelight;

            var inputPal = new LPanel
                (
                parentpal,
                lineint,
                size,
                point,
                Linecolor,
                Backcolor,
                anchorstyle
                );
            inputPal.Controls.Add(this);
            var inputdesc = new LButton
                (
                inputPal,
                0,
                predesc,
                descfont,
                descsize,
                new Point(size.Width - descsize.Width, -1),
                debkcolor,
                debkcolor,
                debkcolor,
                Color.FromArgb(51, debkcolor),
                defrcolor,
                defrcolor,
                AnchorStyles.Right | AnchorStyles.Top |
                AnchorStyles.Bottom
                );

            inputdesc.Focus();
            inputdesc.MouseClick += searchEnter;
            PreWord = preword;
            Text = preword;
            Multiline = false;
            Size = new Size(inputPal.Size.Width - 8*lineint - descsize.Width,
                            inputPal.Size.Height - 4*lineint);
            Location = new Point(4*lineint, (4 + lineflo)*lineint);
            BackColor = Backcolor;
            ForeColor = Forecolor;
            Font = font;
            Anchor = anchorstyle;
            AllowDrop = true;
            DragEnter += FPanel_DragEnter;

            Leave += LInput_Leave;
            Enter += LInput_Enter;
            KeyDown += searchEnterKey;
            GotFocus += InputBoxWithDesc_GotFocus;
            LostFocus += InputBoxWithDesc_LostFocus;
        }
Пример #44
0
 public static Rectangle Align(Size alignThis, Rectangle withinThis, AnchorStyles anchorStyles)
 {
     return(VAlign(alignThis, HAlign(alignThis, withinThis, anchorStyles), anchorStyles));
 }
        public LPanel(
            Control parentpal,
            int lineint,
            Size size,
            Point point,
            Color linecolor,
            Color backcolor,
            AnchorStyles anchorstyle
            )
        {
            var panelSec = new HPanel
                {
                    Size = size,
                    Location = point,
                    Anchor = anchorstyle,
                    BackColor = linecolor,
                };
            Size = new Size(panelSec.Size.Width - 2*lineint, panelSec.Size.Height - 2*lineint);
            Location = new Point(lineint, lineint);
            BackColor = backcolor;
            Anchor = AnchorStyles.Top | AnchorStyles.Left |
                     AnchorStyles.Right | AnchorStyles.Bottom;

            panelSec.Controls.Add(this);
            parentpal.Controls.Add(panelSec);
        }
Пример #46
0
 public static Rectangle AlignAndStretch(Size fitThis, Rectangle withinThis, AnchorStyles anchorStyles)
 {
     return(Align(Stretch(fitThis, withinThis.Size, anchorStyles), withinThis, anchorStyles));
 }
Пример #47
0
 public static bool IsAnchored(AnchorStyles anchor, AnchorStyles desiredAnchor)
 {
     return((anchor & desiredAnchor) == desiredAnchor);
 }
Пример #48
0
        public static void SetAnchor(IArrangedElement container, IArrangedElement element, AnchorStyles value)
        {
            AnchorStyles oldValue = GetAnchor(element);

            if (oldValue != value)
            {
                if (CommonProperties.GetNeedsDockLayout(element))
                {
                    // We set dock back to none to cause the element to size back to its original bounds.
                    SetDock(element, DockStyle.None);
                }

                CommonProperties.xSetAnchor(element, value);

                if (CommonProperties.GetNeedsAnchorLayout(element))
                {
                    UpdateAnchorInfo(element);
                }
                else
                {
                    SetAnchorInfo(element, null);
                }

                if (element.Container is not null)
                {
                    bool rightReleased  = IsAnchored(oldValue, AnchorStyles.Right) && !IsAnchored(value, AnchorStyles.Right);
                    bool bottomReleased = IsAnchored(oldValue, AnchorStyles.Bottom) && !IsAnchored(value, AnchorStyles.Bottom);
                    if (element.Container.Container is not null && (rightReleased || bottomReleased))
                    {
                        // If the right or bottom anchor is being released, we have a special case where the element's
                        // margin may affect preferredSize where it didn't previously. Rather than do an expensive
                        // check for this in OnLayout, we just detect the case her and force a relayout.
                        LayoutTransaction.DoLayout(element.Container.Container, element, PropertyNames.Anchor);
                    }

                    LayoutTransaction.DoLayout(element.Container, element, PropertyNames.Anchor);
                }
            }
        }
Пример #49
0
        protected override void WndProc(ref Message m)
        {
            switch (m.Msg)
            {
            //        case WM_NCLBUTTONDBLCLK:
            //            base.WndProc(ref m);
            //            if (m.Result == HTCLIENT)
            //            {
            //                Form newForm1 = CheckMdiFormIsOpen("StartProccess");
            //                if (newForm1 == null)
            //                {
            //                    StartProccess from = new StartProccess();
            //                    from.Show();
            //                }
            //                else
            //                {
            //                    newForm1.WindowState = FormWindowState.Normal;
            //                    newForm1.Show();
            //                }
            //            }
            //            break;
            //        case WM_NCHITTEST:

            //            base.WndProc(ref m);


            //            if (m.Result == HTCLIENT)
            //            {
            //                m.Result = HTCAPTION;

            //                return;
            //            }


            //            // return;
            //            break;
            //        case WM_RBUTTONDOWN:
            //            base.WndProc(ref m);
            //            MessageBox.Show("右击事件");

            //            break;
            case WM_MOVING:     // 窗体移动的消息,控制窗体不会移出屏幕外


                int left   = Marshal.ReadInt32(m.LParam, 0);
                int top    = Marshal.ReadInt32(m.LParam, 4);
                int right  = Marshal.ReadInt32(m.LParam, 8);
                int bottom = Marshal.ReadInt32(m.LParam, 12);
                left = Math.Min(Math.Max(0, left),
                                Screen.PrimaryScreen.Bounds.Width - Width);
                top = Math.Min(Math.Max(0, top),
                               Screen.PrimaryScreen.Bounds.Height - Height);
                right = Math.Min(Math.Max(Width, right),
                                 Screen.PrimaryScreen.Bounds.Width);
                bottom = Math.Min(Math.Max(Height, bottom),
                                  Screen.PrimaryScreen.Bounds.Height);
                Marshal.WriteInt32(m.LParam, 0, left);
                Marshal.WriteInt32(m.LParam, 4, top);
                Marshal.WriteInt32(m.LParam, 8, right);
                Marshal.WriteInt32(m.LParam, 12, bottom);
                anchors = AnchorStyles.None;
                if (left <= OFFSET)
                {
                    anchors |= AnchorStyles.Left;
                }
                if (top <= OFFSET)
                {
                    anchors |= AnchorStyles.Top;
                }
                if (bottom >= Screen.PrimaryScreen.Bounds.Height - OFFSET)
                {
                    anchors |= AnchorStyles.Bottom;
                }
                if (right >= Screen.PrimaryScreen.Bounds.Width - OFFSET)
                {
                    anchors |= AnchorStyles.Right;
                }
                timer1.Enabled = anchors != AnchorStyles.None;
                break;
            }
            base.WndProc(ref m);
        }
Пример #50
0
        private static Size GetAnchorPreferredSize(IArrangedElement container)
        {
            Size prefSize = Size.Empty;

            ArrangedElementCollection children = container.Children;

            for (int i = children.Count - 1; i >= 0; i--)
            {
                IArrangedElement element = container.Children[i];
                if (!CommonProperties.GetNeedsDockLayout(element) && element.ParticipatesInLayout)
                {
                    AnchorStyles anchor       = GetAnchor(element);
                    Padding      margin       = CommonProperties.GetMargin(element);
                    Rectangle    elementSpace = LayoutUtils.InflateRect(GetCachedBounds(element), margin);

                    if (IsAnchored(anchor, AnchorStyles.Left) && !IsAnchored(anchor, AnchorStyles.Right))
                    {
                        // If we are anchored to the left we make sure the container is large enough not to clip us
                        // (unless we are right anchored, in which case growing the container will just resize us.)
                        prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right);
                    }

                    if (!IsAnchored(anchor, AnchorStyles.Bottom))
                    {
                        // If we are anchored to the top we make sure the container is large enough not to clip us
                        // (unless we are bottom anchored, in which case growing the container will just resize us.)
                        prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom);
                    }

                    if (IsAnchored(anchor, AnchorStyles.Right))
                    {
                        // If we are right anchored, see what the anchor distance between our right edge and
                        // the container is, and make sure our container is large enough to accomodate us.
                        Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true);
                        if (anchorDest.Width < 0)
                        {
                            prefSize.Width = Math.Max(prefSize.Width, elementSpace.Right + anchorDest.Width);
                        }
                        else
                        {
                            prefSize.Width = Math.Max(prefSize.Width, anchorDest.Right);
                        }
                    }

                    if (IsAnchored(anchor, AnchorStyles.Bottom))
                    {
                        // If we are right anchored, see what the anchor distance between our right edge and
                        // the container is, and make sure our container is large enough to accomodate us.
                        Rectangle anchorDest = GetAnchorDestination(element, Rectangle.Empty, /*measureOnly=*/ true);
                        if (anchorDest.Height < 0)
                        {
                            prefSize.Height = Math.Max(prefSize.Height, elementSpace.Bottom + anchorDest.Height);
                        }
                        else
                        {
                            prefSize.Height = Math.Max(prefSize.Height, anchorDest.Bottom);
                        }
                    }
                }
            }

            return(prefSize);
        }