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


C# DrawItemEventArgs.DrawFocusRectangle方法代码示例

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


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

示例1: cbox_DisplayPictures_DrawItem

 private void cbox_DisplayPictures_DrawItem(object sender, DrawItemEventArgs e)
 {
     if (G_ImageList != null)//判断ImageList是否为空
     {
         Graphics g = e.Graphics;//得到绘图对象
         Rectangle r = e.Bounds;//得到绘图范围
         Size imageSize = G_ImageList.ImageSize;//获取图像大小
         if (e.Index >= 0)//判断是否有绘制项
         {
             Font fn = new Font("宋体", 10, FontStyle.Bold);//创建字体对象
             string s = cbox_DisplayPictures.Items[e.Index].ToString();//得到绘制项的字符串
             DrawItemState dis = e.State;
             if (e.State == (DrawItemState.NoAccelerator | DrawItemState.NoFocusRect))
             {
                 e.Graphics.FillRectangle(new SolidBrush(Color.LightYellow), r);//画条目背景
                 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
                 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
                     r.Left + imageSize.Width, r.Top);
                 e.DrawFocusRectangle();//显示取得焦点时的虚线框
             }
             else
             {
                 e.Graphics.FillRectangle(new SolidBrush(Color.LightGreen), r);//画条目背景
                 G_ImageList.Draw(e.Graphics, r.Left, r.Top, e.Index);//绘制图像
                 e.Graphics.DrawString(s, fn, new SolidBrush(Color.Black),//显示字符串
                     r.Left + imageSize.Width, r.Top);
                 e.DrawFocusRectangle();//显示取得焦点时的虚线框
             }
         }
     }
 }
开发者ID:TGHGH,项目名称:C-1200,代码行数:31,代码来源:Frm_Main.cs

示例2: QuickSearchComboBox_DrawItem

		/// <summary>
		/// drawns the icon and the name of the element in the dropdown list
		/// </summary>
		/// <param name="sender">the sender</param>
		/// <param name="e">the params</param>
		private void QuickSearchComboBox_DrawItem(object sender, DrawItemEventArgs e)
        { 
			//get the selected element and its associated image
			if (0 <= e.Index && e.Index  < this.Items.Count)
			{
				UML.UMLItem selectedElement = this.Items[e.Index] as UML.UMLItem;
				if (selectedElement != null)
				{
					Image elementImage = this.navigatorVisuals.getImage(selectedElement);
					//draw standard background and focusrectangle
					e.DrawBackground();
					e.DrawFocusRectangle();		
								
					//draw the name of the element
					e.Graphics.DrawString(this.navigatorVisuals.getNodeName(selectedElement), e.Font, new SolidBrush(e.ForeColor),
		                                  new Point(elementImage.Width + 2,e.Bounds.Y)); 
		            // draw the icon
		            e.Graphics.DrawImage(elementImage, new Point(e.Bounds.X, e.Bounds.Y));   
		            
		            // draw tooltip
		            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
		            {
		            	 this.itemTooltip.Show(selectedElement.fqn,
                            this, e.Bounds.Right, e.Bounds.Bottom);
		            }
		            else
		            {
		            	this.itemTooltip.Hide(this);
		            }
				}
			}
             
        }
开发者ID:Helmut-Ortmann,项目名称:Enterprise-Architect-Toolpack,代码行数:38,代码来源:QuickSearchComboBox.cs

示例3: OnDrawItem

  protected override void OnDrawItem( DrawItemEventArgs e )
  {
   e.DrawBackground();
   e.DrawFocusRectangle();

   if( e.Index > -1 )
   {
    ComboBoxItem itm = (( ComboBoxItem ) Items[ e.Index ]);
    int x = e.Bounds.Left + ( 16 - itm.Img.Width ) / 2,
        y = ( 15 - itm.Img.Height ) / 2,
        w = itm.Img.Width,
        h = itm.Img.Height;

    x = ( x > 0 ) ? x : 0;
    y = (( y > 0 ) ? y : 0 ) + e.Bounds.Top;
    w = ( w > 15 ) ? 15 : w;
    h = ( h > 15 ) ? 15 : h;

    e.Graphics.DrawImage( itm.Img,
                          new Rectangle( x, y, w, h ),
                          new Rectangle( 0, 0, itm.Img.Width, itm.Img.Height ),
                          GraphicsUnit.Pixel );
    e.Graphics.DrawString( itm.Text,
                           e.Font,
                           new SolidBrush( e.ForeColor ),
                           x + w,
                           e.Bounds.Top + 2 );

   }

   base.OnDrawItem( e );

  }
开发者ID:InTheSPOT,项目名称:creative-mode-plus,代码行数:33,代码来源:ComboBoxWithIcons.cs

示例4: OnDrawItem

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.ListBox.DrawItem"/> event.
        /// </summary>
        /// <param name="e">A <see cref="T:System.Windows.Forms.DrawItemEventArgs"/> that contains the event data.</param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            if (DesignMode)
            {
                base.OnDrawItem(e);
                return;
            }

            // Get the selected emitter to draw
            var emitter = (e.Index < 0 || e.Index >= Items.Count ? null : Items[e.Index]) as IParticleEmitter;

            // Let the base implementation handle an invalid item
            if (emitter == null)
            {
                base.OnDrawItem(e);
                return;
            }

            // Draw the item
            e.DrawBackground();

            var txt = string.Format(_displayTextFormat, emitter.GetType().Name, emitter.Name);
            using (var brush = new SolidBrush(e.ForeColor))
            {
                e.Graphics.DrawString(txt, e.Font, brush, e.Bounds);
            }

            e.DrawFocusRectangle();
        }
开发者ID:wtfcolt,项目名称:game,代码行数:33,代码来源:ParticleEmitterListBox.cs

示例5: xxcbDrawItem

        private void xxcbDrawItem(object sender, DrawItemEventArgs e)
        {
            //drawItems here
            if (sender == null)
                return;
            if (e.Index < 0)
                return;
            //Get the Combo from the sender object
            ComboBox cbo = (ComboBox)sender;
            //Get the FontFamily from put in constructor
            FontFamily ff = new FontFamily(cbo.Items[e.Index].ToString());
            //Set font style
            FontStyle fs = FontStyle.Regular;
            if (!ff.IsStyleAvailable(fs))
                fs = FontStyle.Italic;
            if (!ff.IsStyleAvailable(fs))
                fs = FontStyle.Bold;
            //Set font for drawing with (wich is the font itself)
            Font font = new Font(ff, 8, fs);

            //draw the background and focus rectangle
            e.DrawBackground();
            e.DrawFocusRectangle();
            //get graphics
            Graphics g = e.Graphics;
            //And draw with whatever font and brush we wish
            g.DrawString(font.Name, font, Brushes.ForestGreen, e.Bounds.X, e.Bounds.Y);

        }
开发者ID:dbbotkin,项目名称:PrimeComm,代码行数:29,代码来源:FontBrowser.cs

示例6: OnDrawItem

 /// <summary>
 /// Custom Draw Item Handler.
 /// It fires when painting each item in dropdown list. We use item value (text) to create the path to picture in resource and paint it in the list.
 /// </summary>
 /// <param name="e">Arguments from DrawItem Event</param>
 protected override void OnDrawItem(DrawItemEventArgs e)
 {
     // Draw background and focus rectangle, if necessary.
     e.DrawBackground();
     e.DrawFocusRectangle();
     // If something is selected, paint it
     if (e.Index > -1)
     {
         // Get text from current item
         var text     = (string)Items[e.Index];
         // Get resource path to picture
         var resource = string.Format("HSCardGenerator.Resources.Images.Flags.{0}.png", text.ToLower());
         // Read it as stream
         using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource))
         {
             // And paint it
             e.Graphics.DrawImage(Image.FromStream(stream), new PointF(e.Bounds.X, e.Bounds.Y));
         }
         // Draw text if necessary
         if (showLabels)
         {
             // Same as for OnPaint event
             var txt    = Config.localesFull[(int)Methods.General.getLocaleFromString(text)];
             var limits = e.Graphics.MeasureString(txt, e.Font);
             var top    = (24 - limits.Height) / 2;
             e.Graphics.DrawString(txt, e.Font, new SolidBrush(e.ForeColor), e.Bounds.Left + 24, e.Bounds.Top + top);
         }
         // We need to do this, no wonder why :/
         if ((e.Index == SelectedIndex) && (DroppedDown == false))
         {
             e.DrawFocusRectangle();
         }
     }
 }
开发者ID:hugojcastro,项目名称:HSCardCreator,代码行数:39,代码来源:FlagComboBox.cs

示例7: OnDrawItem

        /// <summary>
        /// OnDrawItem override to draw our custom item.
        /// </summary>
        /// <param name="e"></param>
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            // Validation check to prevent designer errors..
            if (this.Items.Count <= 0)
                return;

            // Cast the incoming argument as a buff entry..
            var buff = (Buff)this.Items[e.Index];

            // Adjust the background based on selection..
            e.Graphics.FillRectangle((e.State & DrawItemState.Selected) == DrawItemState.Selected ?
                Brushes.SkyBlue : Brushes.White, e.Bounds);

            // Draw seperator line..
            e.Graphics.DrawLine(Pens.Black, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y);

            // Draw the buff icon..
            var bmp = new Bitmap(buff.Icon.LocalPath);
            e.Graphics.DrawImage(bmp, e.Bounds.X + this.Margin.Left, e.Bounds.Y + this.Margin.Top, 32, 32);

            // Calculate name string bounds..
            var nameBounds = new Rectangle(e.Bounds.X + this.Margin.Horizontal + 32,
                                           e.Bounds.Y + this.Margin.Top,
                                           e.Bounds.Width - this.Margin.Right - 32 - this.Margin.Horizontal,
                                           (int)this.Font.GetHeight() + 2);

            // Draw buff information strings..
            e.Graphics.DrawString(buff.Name, this.Font, Brushes.Black, nameBounds);

            // Draw the focused item rect..
            e.DrawFocusRectangle();
        }
开发者ID:Walkman-Mirror,项目名称:TSGE,代码行数:36,代码来源:BuffSelectionList.cs

示例8: this_DrawItem

 private void this_DrawItem(object sender, DrawItemEventArgs e) {
     if (e.Index == -1) return;
     e.DrawBackground();
     if ((e.State & DrawItemState.Selected) != 0) {
         e.Graphics.FillRectangle(_highlightbrush, e.Bounds);
     }
     EXItem item = (EXItem) this.Items[e.Index];
     Rectangle bounds = e.Bounds;
     int x = bounds.X + 2;
     if (item.GetType() == typeof(EXImageItem)) {
         EXImageItem imgitem = (EXImageItem) item;
         if (imgitem.MyImage != null) {
             Image img = imgitem.MyImage;
             int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1;
             e.Graphics.DrawImage(img, x, y, img.Width, img.Height);
             x += img.Width + 2;
         }
     } else if (item.GetType() == typeof(EXMultipleImagesItem)) {
         EXMultipleImagesItem imgitem = (EXMultipleImagesItem) item; 
         if (imgitem.MyImages != null) {
             for (int i = 0; i < imgitem.MyImages.Count; i++) {
                 Image img = (Image) imgitem.MyImages[i];
                 int y = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (img.Height / 2)) + 1;
                 e.Graphics.DrawImage(img, x, y, img.Width, img.Height);
                 x += img.Width + 2;
             }
         }
     }
     int fonty = bounds.Y + ((int) (bounds.Height / 2)) - ((int) (e.Font.Height / 2));
     e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), x, fonty);
     e.DrawFocusRectangle();
 }
开发者ID:hmaster20,项目名称:mRemoteNC,代码行数:32,代码来源:EXComboBox.cs

示例9: PcListBox_DrawItem_1

        private void PcListBox_DrawItem_1(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            e.DrawFocusRectangle();

            if (e.Index >= 0)
            {
                var ListBox = (ListBox)sender;
                var item = ListBox.Items[e.Index] as PCItem;

                var Color = item.ItemColor;

                if (item == ListBox.SelectedItem)
                {
                    //Color = SystemColors.HighlightText;
                }

                e.Graphics.DrawString(
                    item.ToString(),
                    ListBox.Font,
                    new SolidBrush(Color),
                    e.Bounds
                );
            }
        }
开发者ID:soywiz,项目名称:cspspemu,代码行数:25,代码来源:FunctionViewerForm.cs

示例10: OnDrawItem

 protected override void OnDrawItem(DrawItemEventArgs e)
 {
     e.DrawBackground();
     e.DrawFocusRectangle();
     try
     {
         Image image = (Image)this.Items[e.Index];
         Rectangle rec = e.Bounds;
         rec.Height -= 2;
         rec.Width -= 2;
         rec.X += 1;
         rec.Y += 1;
         e.Graphics.DrawImage(image, rec);
     }
     catch
     {
         if (e.Index != -1)
         {
             //不是图片则显示字符
             e.Graphics.DrawString(Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y);
         }
     }
     finally
     {
         base.OnDrawItem(e);
     }
 }
开发者ID:Shen001,项目名称:AEWinForm,代码行数:27,代码来源:Custom_ColorRampCombobox.cs

示例11: ColorComboBox_DrawItem

		void ColorComboBox_DrawItem(object sender, DrawItemEventArgs e)
		{
			e.DrawBackground();
			if (e.Index >= 0)
			{
				Rectangle rectangle = new Rectangle(4, e.Bounds.Top + 2, 30, e.Bounds.Height - 4);
				Color rectColor = (Color)Items[e.Index];
				e.Graphics.FillRectangle(new SolidBrush(rectColor), rectangle);
				e.Graphics.DrawRectangle(System.Drawing.Pens.Black, rectangle);
				if (e.Index == 0)
				{
					e.Graphics.DrawString("Custom", e.Font, System.Drawing.Brushes.Black,
						new PointF(42, e.Bounds.Top + 2));
				}
				else
				{
					e.Graphics.DrawString(((Color)Items[e.Index]).Name, e.Font, System.Drawing.Brushes.Black,
						new PointF(42, e.Bounds.Top + 2));
				}
				if (!Enabled)
				{
					HatchBrush brush = new HatchBrush(HatchStyle.Percent50, Color.LightGray, Color.FromArgb(10, Color.LightGray));
					rectangle.Inflate(1, 1);
					e.Graphics.FillRectangle(brush, rectangle);
					brush.Dispose();
				}
				e.DrawFocusRectangle();
			}
		}
开发者ID:gspatace,项目名称:logexpert,代码行数:29,代码来源:ColorComboBox.cs

示例12: DrawItemHandler

		private void DrawItemHandler(object sender, DrawItemEventArgs e)
		{
			RectangleF rc = new RectangleF((float)(e.Bounds.X), (float)(e.Bounds.Y), (float)(e.Bounds.Width), (float)(e.Bounds.Height));
			e.Graphics.FillRectangle(new SolidBrush(SystemColors.Control), rc);
			MenuItem s = (MenuItem)sender;
			string s1 = s.Text;
			StringFormat sf = new StringFormat();
			RectangleF rcText = rc;
			rcText.Y += 2;
			rcText.X += 24;
			rcText.Width -= 20;
			if (e.State == (DrawItemState.NoAccelerator | DrawItemState.Selected))
			{
				e.Graphics.FillRectangle(new SolidBrush(SystemColors.Highlight), rc);
				e.Graphics.DrawString(s1, CurrentFont, new SolidBrush(SystemColors.HighlightText), rcText, sf);
				e.DrawFocusRectangle();
			}
			else
			{
				e.Graphics.DrawString(s1, CurrentFont, new SolidBrush(SystemColors.ControlText), rcText, sf);
			}

			if (Ico != null)
			{
				e.Graphics.DrawImage(Ico, System.Convert.ToInt32(e.Bounds.X + 5), System.Convert.ToInt32((e.Bounds.Bottom + e.Bounds.Top) / 2 - Ico.Size.Height / 2));
			}
		}
开发者ID:aureliopires,项目名称:gisa,代码行数:27,代码来源:PXMenuItem.cs

示例13: ComboBox_DrawItem

        /// <summary>
        /// This method will draw the items of the DropDownList. It will draw the Icon and the text and
        /// with the indent that goes with the item
        /// </summary>
        void ComboBox_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index == -1)
                return;
            else
            {
                BrowserComboItem item = (BrowserComboItem)Items[e.Index];

                e.DrawBackground();
                e.DrawFocusRectangle();

                int indentOffset = indentWidth * item.Indent;

                int imageYOffset = (e.Bounds.Height - item.Image.Height) / 2;
                Point imagePoint = new Point(
                    e.Bounds.Left + indentOffset + 2,
                    e.Bounds.Top + imageYOffset);

                Size textSize = e.Graphics.MeasureString(item.Text, Font).ToSize();
                int textYOffset = (e.Bounds.Height - textSize.Height) / 2;
                Point textPoint = new Point(
                    e.Bounds.Left + item.Image.Width + indentOffset + 2,
                    e.Bounds.Top + textYOffset);

                e.Graphics.DrawIcon(item.Image, imagePoint.X, imagePoint.Y);
                e.Graphics.DrawString(item.Text, e.Font, new SolidBrush(e.ForeColor), textPoint);
            }
        }
开发者ID:xeno-by,项目名称:datavault,代码行数:32,代码来源:BrowserComboBox.cs

示例14: ServerIDTypeCB_DrawItem

        /// <summary>
        /// Draw device ID types.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ServerIDTypeCB_DrawItem(object sender, DrawItemEventArgs e)
        {
            // If the index is invalid then simply exit.
            if (e.Index == -1 || e.Index >= AddressTypeCB.Items.Count)
            {
                return;
            }

            // Draw the background of the item.
            e.DrawBackground();

            // Should we draw the focus rectangle?
            if ((e.State & DrawItemState.Focus) != 0)
            {
                e.DrawFocusRectangle();
            }

            Font f = new Font(e.Font, FontStyle.Regular);
            // Create a new background brush.
            Brush b = new SolidBrush(e.ForeColor);
            // Draw the item.			
            GXServerAddress target = (GXServerAddress)AddressTypeCB.Items[e.Index];
            if (target == null)
            {
                return;
            }
            string name = target.HDLCAddress.ToString();
            SizeF s = e.Graphics.MeasureString(name, f);
            e.Graphics.DrawString(name, f, b, e.Bounds);
        }
开发者ID:giapdangle,项目名称:Gurux.DLMS.AddIn,代码行数:35,代码来源:GXDLMSDeviceUI.cs

示例15: annotationListBox_DrawItem

        private void annotationListBox_DrawItem( object sender, DrawItemEventArgs e )
        {
            e.DrawBackground();
            AnnotationListItem item = (AnnotationListItem) annotationListBox.Items[e.Index];
            e.Graphics.DrawString( item.annotation.Point.ToString("f3"),
                annotationListBox.Font,
                new SolidBrush( annotationListBox.ForeColor ),
                new PointF( (float) e.Bounds.X, (float) e.Bounds.Y ) );

            string label;
            if( item.annotation.Label.Contains(" ") )
                label = "\"" + item.annotation.Label + "\"";
            else
                label = item.annotation.Label;
            e.Graphics.DrawString( label,
                annotationListBox.Font,
                new SolidBrush( annotationListBox.ForeColor ),
                new PointF( (float) e.Bounds.X + ( ( e.Bounds.Width / 2 ) - ( e.Bounds.Height * 2 ) ), (float) e.Bounds.Y ) );

            Rectangle colorSampleBox = new Rectangle( e.Bounds.Location, e.Bounds.Size );
            colorSampleBox.X = e.Bounds.Right - e.Bounds.Height * 2;
            colorSampleBox.Location.Offset( -5, 0 );
            e.Graphics.FillRectangle( new SolidBrush( ownerGraphForm.ZedGraphControl.GraphPane.Chart.Fill.Color ), colorSampleBox );
            int middle = colorSampleBox.Y + colorSampleBox.Height / 2;
            e.Graphics.DrawLine( new Pen( item.annotation.Color, item.annotation.Width ), colorSampleBox.Left, middle, colorSampleBox.Right, middle );
            e.DrawFocusRectangle();
        }
开发者ID:pombredanne,项目名称:BICEPS,代码行数:27,代码来源:AnnotationEditForm.cs


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