当前位置: 首页>>代码示例>>C#>>正文


C# DataGridViewElementStates.HasFlag方法代码示例

本文整理汇总了C#中DataGridViewElementStates.HasFlag方法的典型用法代码示例。如果您正苦于以下问题:C# DataGridViewElementStates.HasFlag方法的具体用法?C# DataGridViewElementStates.HasFlag怎么用?C# DataGridViewElementStates.HasFlag使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DataGridViewElementStates的用法示例。


在下文中一共展示了DataGridViewElementStates.HasFlag方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BeforePaintContent

        /// <summary>
        /// Paints common elements behind the cell content.
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="cellBounds"></param>
        /// <param name="cellState"></param>
        /// <param name="cellStyle"></param>
        /// <param name="paintParts"></param>
        protected void BeforePaintContent(Graphics graphics, Rectangle cellBounds, DataGridViewElementStates cellState, DataGridViewCellStyle cellStyle, DataGridViewPaintParts paintParts)
        {
            if (paintParts.HasFlag(DataGridViewPaintParts.Background)) {
                using (Brush brush = new SolidBrush(cellStyle.BackColor)) {
                    graphics.FillRectangle(brush, cellBounds);
                }
            }

            if (paintParts.HasFlag(DataGridViewPaintParts.SelectionBackground) && cellState.HasFlag(DataGridViewElementStates.Selected)) {
                using (Brush brush = new SolidBrush(cellStyle.SelectionBackColor)) {
                    graphics.FillRectangle(brush, cellBounds);
                }
            }

            if (paintParts.HasFlag(DataGridViewPaintParts.ContentBackground)) {
                ComboBoxState state = ComboBoxState.Normal;
                ButtonState legacyState = ButtonState.Normal;

                if ((DataGridView.Site == null) || !DataGridView.Site.DesignMode) {
                    if (cellState.HasFlag(DataGridViewElementStates.ReadOnly)) {
                        state = ComboBoxState.Disabled;
                        legacyState = ButtonState.Inactive;
                    }
                    else if (cellBounds.Contains(DataGridView.PointToClient(DataGridView.MousePosition))) {
                        if (DataGridView.MouseButtons.HasFlag(MouseButtons.Left)) {
                            state = ComboBoxState.Pressed;
                            legacyState = ButtonState.Pushed;
                        }
                        else {
                            state = ComboBoxState.Hot;
                        }
                    }
                }

                Rectangle comboBounds = cellBounds;
                comboBounds.Width--;

                if (((DropDownColumnBase)OwningColumn).BufferedPaintingSupported) {
                    GroupedComboBox.DrawComboBox(graphics, comboBounds, state);
                }
                else {
                    DropDownControlBase.DrawLegacyComboBox(graphics, comboBounds, DropDownControlBase.GetComboButtonBounds(comboBounds), cellStyle.BackColor, legacyState);
                }
            }
        }
开发者ID:zwolsman,项目名称:proftaak,代码行数:53,代码来源:DropDownColumnBase.cs

示例2: Paint

        /// <summary>
        /// 
        /// </summary>
        /// <param name="graphics"></param>
        /// <param name="clipBounds"></param>
        /// <param name="cellBounds"></param>
        /// <param name="rowIndex"></param>
        /// <param name="elementState"></param>
        /// <param name="value"></param>
        /// <param name="formattedValue"></param>
        /// <param name="errorText"></param>
        /// <param name="cellStyle"></param>
        /// <param name="advancedBorderStyle"></param>
        /// <param name="paintParts"></param>
        protected override void Paint(Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, DataGridViewElementStates elementState, object value, object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts)
        {
            // 背景の描画
            graphics.FillRectangle(elementState.HasFlag(DataGridViewElementStates.Selected) ? new SolidBrush(cellStyle.SelectionBackColor) : new SolidBrush(cellStyle.BackColor), cellBounds);

            // ボーダーの描画
            base.PaintBorder(graphics, clipBounds, cellBounds, cellStyle, advancedBorderStyle);

            Items.Clear();
            if (!StringUtility.IsEmpty(value))
            {
                int x = cellBounds.X;

                var buttons = value.ToString().Split(',');
                for (int i = 0; i < buttons.Length; i++)
                {
                    string b = buttons[i];
                    if (string.IsNullOrEmpty(b))
                        continue;

                    // テキストの幅を取得
                    int textWidth = (int)graphics.MeasureString(b, cellStyle.Font).Width + 4;

                    // アングルを取得
                    Rectangle angle = new Rectangle(x, cellBounds.Y, textWidth, cellBounds.Height);

                    // アイテムに追加
                    Items.Add(new DataGridViewMultiButton(i, b, angle));

                    // ボタンを描画
                    ButtonRenderer.DrawButton(graphics, new Rectangle(x, cellBounds.Y, textWidth, cellBounds.Height), b, cellStyle.Font, base.DataGridView.CurrentCell == this, PushButtonState.Normal);

                    // 次のボタンを表示するx座標を設定
                    x += textWidth + 2;
                }
            }
        }
开发者ID:Ricordanza,项目名称:Ricordanza.kernel,代码行数:51,代码来源:DataGridViewMultiButtonColumn.cs

示例3: Paint

		//-------------------------------------------------------------------------------------
		#region << Methods >>
		/// <summary>
		/// Paint
		/// </summary>
		protected override void Paint(Graphics g, Rectangle clipBounds, Rectangle cellBounds, int rowIndex,
				DataGridViewElementStates cellState, object value, object formattedValue, string errorText, 
				DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, 
				DataGridViewPaintParts paintParts)
		{
			if(OwningColumn is SimDataGridViewLabelColumn == false || DataGridView is SimDataGridView == false)
			{ 
				base.Paint(g, clipBounds, cellBounds, rowIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts);
				return;
			}
			
			Rectangle r = cellBounds;

			Image img = ((SimDataGridView)DataGridView).OnNeedCellImage(rowIndex,OwningColumn.Index,
																			((SimDataGridViewLabelColumn)OwningColumn).Image);
			int imgWidth = 0;
			if(img != null)
				imgWidth = img.Width < 5 ? 7 : img.Width + 2;

			if(((SimDataGridViewLabelColumn)OwningColumn).IsLeftImageAlign)
			{
				r.Width -= imgWidth+2;
				r.X += imgWidth+2;
			}
			else
				r.Width -= imgWidth;
			SolidBrush b;

			// Фон 
			if(cellState.HasFlag(DataGridViewElementStates.Selected))
				b = new SolidBrush(cellStyle.SelectionBackColor);
			else	if(OwningColumn.DataGridView.Enabled == false)
				b = new SolidBrush(SystemColors.Control);
			else
				b = new SolidBrush(cellStyle.BackColor);
			using(b)
				g.FillRectangle(b, cellBounds);

			// Рамки
			base.PaintBorder(g,clipBounds,cellBounds,cellStyle, advancedBorderStyle );

			// Текст
			//StringFormat sf = new StringFormat() { Trimming = StringTrimming.EllipsisCharacter,
			//                                       FormatFlags = StringFormatFlags.NoWrap
			//                                     };

			//#region StringFormat
			//switch(cellStyle.Alignment)
			//{
			// case DataGridViewContentAlignment.BottomCenter:
			// tf |= TextFormatFlags.
			//  break;
			// case DataGridViewContentAlignment.BottomLeft:
			//  sf.Alignment = StringAlignment.Near;
			//  sf.LineAlignment = StringAlignment.Far;
			//  break;
			// case DataGridViewContentAlignment.BottomRight:
			//  sf.Alignment = StringAlignment.Far;
			//  sf.LineAlignment = StringAlignment.Far;
			//  break;
			// case DataGridViewContentAlignment.MiddleCenter:
			//  sf.Alignment = StringAlignment.Center;
			//  sf.LineAlignment = StringAlignment.Center;
			//  break;
			// case DataGridViewContentAlignment.MiddleLeft:
			//  sf.Alignment = StringAlignment.Near;
			//  sf.LineAlignment = StringAlignment.Center;
			//  break;
			// case DataGridViewContentAlignment.MiddleRight:
			//  sf.Alignment = StringAlignment.Far;
			//  sf.LineAlignment = StringAlignment.Center;
			//  break;
			// case DataGridViewContentAlignment.TopCenter:
			//  sf.Alignment = StringAlignment.Center;
			//  sf.LineAlignment = StringAlignment.Near;
			//  break;
			// case DataGridViewContentAlignment.TopLeft:
			//  sf.Alignment = StringAlignment.Near;
			//  sf.LineAlignment = StringAlignment.Near;
			//  break;
			// case DataGridViewContentAlignment.TopRight:
			//  sf.Alignment = StringAlignment.Far;
			//  sf.LineAlignment = StringAlignment.Near;
			//  break;
			// default: goto case DataGridViewContentAlignment.MiddleLeft;
			//} 
			//#endregion StringFormat

			TextFormatFlags tf = TextFormatFlags.EndEllipsis | TextFormatFlags.NoPrefix;
			DataGridViewContentAlignment t = cellStyle.Alignment;
			if(t==DataGridViewContentAlignment.MiddleCenter||t==DataGridViewContentAlignment.MiddleLeft||t==DataGridViewContentAlignment.MiddleRight)
				tf = tf | TextFormatFlags.VerticalCenter;
			if(t == DataGridViewContentAlignment.BottomCenter||t == DataGridViewContentAlignment.BottomLeft||t == DataGridViewContentAlignment.BottomRight)
				tf = tf | TextFormatFlags.Bottom;
			if(t==DataGridViewContentAlignment.BottomCenter||t==DataGridViewContentAlignment.MiddleCenter||t==DataGridViewContentAlignment.TopCenter)
//.........这里部分代码省略.........
开发者ID:GoldMax,项目名称:Pulsar.NET,代码行数:101,代码来源:SimDataGridViewLabelColumn.cs


注:本文中的DataGridViewElementStates.HasFlag方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。