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


C# DateTimePicker.CalculateMaxWidth方法代码示例

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


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

示例1: DrawDateTimePicker

		public override void DrawDateTimePicker(Graphics dc, Rectangle clip_rectangle, DateTimePicker dtp)
		{

			if (!clip_rectangle.IntersectsWith (dtp.ClientRectangle))
				return;

			// draw the outer border
			Rectangle button_bounds = dtp.ClientRectangle;
			DateTimePickerDrawBorder (dtp, dc, clip_rectangle);

			// deflate by the border width
			if (clip_rectangle.IntersectsWith (dtp.drop_down_arrow_rect)) {
				button_bounds.Inflate (-2,-2);
				if (!dtp.ShowUpDown) {
					DateTimePickerDrawDropDownButton (dtp, dc, clip_rectangle);
				} else {
					ButtonState up_state = dtp.is_up_pressed ? ButtonState.Pushed : ButtonState.Normal;
					ButtonState down_state = dtp.is_down_pressed ? ButtonState.Pushed : ButtonState.Normal;
					Rectangle up_bounds = dtp.drop_down_arrow_rect;
					Rectangle down_bounds = dtp.drop_down_arrow_rect;

					up_bounds.Height = up_bounds.Height / 2;
					down_bounds.Y = up_bounds.Height;
					down_bounds.Height = dtp.Height - up_bounds.Height;
					if (down_bounds.Height > up_bounds.Height)
					{
						down_bounds.Y += 1;
						down_bounds.Height -= 1;
					}

					up_bounds.Inflate (-1, -1);
					down_bounds.Inflate (-1, -1);

					ControlPaint.DrawScrollButton (dc, up_bounds, ScrollButton.Up, up_state);
					ControlPaint.DrawScrollButton (dc, down_bounds, ScrollButton.Down, down_state);
				}
			}

			// render the date part
			if (!clip_rectangle.IntersectsWith (dtp.date_area_rect))
				return;

			// fill the background
			dc.FillRectangle (SystemBrushes.Window, dtp.date_area_rect);

			// Update date_area_rect if we are drawing the checkbox
			Rectangle date_area_rect = dtp.date_area_rect;
			if (dtp.ShowCheckBox) {
				Rectangle check_box_rect = dtp.CheckBoxRect;
				date_area_rect.X = date_area_rect.X + check_box_rect.Width + DateTimePicker.check_box_space * 2;
				date_area_rect.Width = date_area_rect.Width - check_box_rect.Width - DateTimePicker.check_box_space * 2;

				ButtonState bs = dtp.Checked ? ButtonState.Checked : ButtonState.Normal;
				CPDrawCheckBox(dc, check_box_rect, bs);

				if (dtp.is_checkbox_selected)
					CPDrawFocusRectangle (dc, check_box_rect, dtp.foreground_color, dtp.background_color);
			}

			// render each text part
			using (StringFormat text_format = StringFormat.GenericTypographic)
			{
				text_format.LineAlignment = StringAlignment.Near;
				text_format.Alignment = StringAlignment.Near;
				text_format.FormatFlags = text_format.FormatFlags | StringFormatFlags.MeasureTrailingSpaces | StringFormatFlags.NoWrap | StringFormatFlags.FitBlackBox;
				text_format.FormatFlags &= ~StringFormatFlags.NoClip;

				// Calculate the rectangles for each part 
				if (dtp.part_data.Length > 0 && dtp.part_data[0].drawing_rectangle.IsEmpty)
				{
					Graphics gr = dc;
					for (int i = 0; i < dtp.part_data.Length; i++)
					{
						DateTimePicker.PartData fd = dtp.part_data[i];
						RectangleF text_rect = new RectangleF();
						string text = fd.GetText(dtp.Value);
						text_rect.Size = gr.MeasureString (text, dtp.Font, 250, text_format);
						if (!fd.is_literal)
							text_rect.Width = Math.Max (dtp.CalculateMaxWidth(fd.value, gr, text_format), text_rect.Width);

						if (i > 0) {
							text_rect.X = dtp.part_data[i - 1].drawing_rectangle.Right;
						} else {
							text_rect.X = date_area_rect.X;
						}
						text_rect.Y = 2;
						text_rect.Inflate (1, 0);
						fd.drawing_rectangle = text_rect;
					}
				}
				
				// draw the text part
				Brush text_brush = ResPool.GetSolidBrush (dtp.ShowCheckBox && dtp.Checked == false ?
						SystemColors.GrayText : dtp.ForeColor); // Use GrayText if Checked is false
				RectangleF clip_rectangleF = clip_rectangle;

				for (int i = 0; i < dtp.part_data.Length; i++)
				{
					DateTimePicker.PartData fd = dtp.part_data [i];
					string text;
//.........这里部分代码省略.........
开发者ID:hindlemail,项目名称:mono,代码行数:101,代码来源:ThemeWin32Classic.cs


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