本文整理汇总了C#中System.Drawing.Rectangle.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# Rectangle.ToString方法的具体用法?C# Rectangle.ToString怎么用?C# Rectangle.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Rectangle
的用法示例。
在下文中一共展示了Rectangle.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: pictureBox1_MouseClick
private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
{
IconRect = GetCurrenIconRect();
IconID = GetCurrenIconID();
label1.Text = IconID.ToString();
label2.Text = IconRect.ToString();
}
示例2: CaptureScreenShot
public Bitmap CaptureScreenShot()
{
Logger.record("[CaptureScreenshot]: Will take a screenshot of the monitor.", "ScreenShot", "info");
Rectangle fullBounds = new Rectangle();
int minX = 0, minY = 0, maxX = 0, maxY = 0;
/*
* Composite desktop calculations for multiple monitors
A, B E, B || E, B
+--------------+ || * +---------------+ D, B
| |E, G || | |
| +---------------+ D, G || +--------------+ E, C |
| | | || |A, C | |
| | | || | | |
| | | || | | |
+--------------+ E, C | || | +---------------+ D, G
A, C | | || | |E, G
+---------------+ D, F || +--------------+ *
E, F || A, F E, F
* We capture from "A, B" to "D, F".
* That is, we look for the minimum X,Y coordinate first.
* Then we look for the largest width,height.
*/
foreach (Screen oneScreen in Screen.AllScreens)
{
Logger.record("\t[CaptureScreenshot]: AllScreens[]: " + oneScreen.Bounds.ToString(), "ScreenShot", "info");
minX = Math.Min(minX, oneScreen.Bounds.Left);
minY = Math.Min(minY, oneScreen.Bounds.Top);
maxX = Math.Max(maxX, oneScreen.Bounds.Width + oneScreen.Bounds.X);
maxY = Math.Max(maxY, oneScreen.Bounds.Height + oneScreen.Bounds.Y);
}
fullBounds = new Rectangle(minX, minY, maxX - minX, maxY - minY);
Logger.record("[CaptureScreenshot]: fullScreen[]: " + fullBounds.ToString(), "ScreenShot", "info");
IntPtr hDesk = GetDesktopWindow();
IntPtr hSrce = GetWindowDC(hDesk);
IntPtr hDest = CreateCompatibleDC(hSrce);
// Our bitmap will have the size of the composite screenshot
IntPtr hBmp = CreateCompatibleBitmap(hSrce, fullBounds.Width, fullBounds.Height);
IntPtr hOldBmp = SelectObject(hDest, hBmp);
// We write on coordinate 0,0 of the bitmap buffer, of course. But we write the the fullBoundsX,Y pixels.
bool b = BitBlt(hDest, 0, 0, fullBounds.Width, fullBounds.Height, hSrce, fullBounds.X, fullBounds.Y, CopyPixelOperation.SourceCopy | CopyPixelOperation.CaptureBlt);
Bitmap bmp = Bitmap.FromHbitmap(hBmp);
SelectObject(hDest, hOldBmp);
DeleteObject(hBmp);
DeleteDC(hDest);
ReleaseDC(hDesk, hSrce);
Logger.record("[CaptureScreenshot]: BMP object ready, returning it to calling function", "ScreenShot", "info");
return (bmp);
}
示例3: Form1
//By James Palmisano
//last edited 1/23/14
//Purpose of app is to show inheritence.
public Form1()
{
InitializeComponent();
//make instance of rectangle class
Rectangle rect = new Rectangle();
rectangleInfo.Text = rect.ToString();
areaOfRectangle.Text = "The area of the retangle is: "
+ Convert.ToString(rect.Area);
//make instance of the circle class
Circle cir = new Circle();
circleInfo.Text = cir.ToString();
circleArea.Text = "The area of the circle is: "
+ Convert.ToString(cir.Area);
}
示例4: Screenshot
public Screenshot(Rectangle r)
{
this.Method = ScreenshotMethod.GDI;
this.TargetRect = r;
this.isMaximized = false;
this.TargetScreen = Screen.FromRectangle(r);
this.BaseScreenshotImage = Core.ScreenshotArea(r);
this.isRounded = false;
this.WindowTitle = "Screenshot (" + r.ToString() + ")";
this.Date = DateTime.Now;
}
示例5: test1
public void test1()
{
Rectangle rect = new Rectangle(10, 12, 14, 16);
// Wrong
System.ComponentModel.TypeConverter baseConverter = new System.ComponentModel.TypeConverter();
string sample1 = baseConverter.ConvertToString(rect);
// Right
System.ComponentModel.TypeConverter rectSpecificConverter = TypeDescriptor.GetConverter(rect);
string sample2 = rectSpecificConverter.ConvertToString(rect);
log.DebugFormat("From new TypeConverter() {0}\r\n", sample1);
log.DebugFormat("From TypeDescriptor.GetConverter() {0}\r\n", sample2);
log.DebugFormat("From rect.ToString() {0}\r\n", rect.ToString());
}
示例6: panel1_MouseMove
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
Rectangle rect1 = new Rectangle(0, 0, e.Location.X, e.Location.Y);
Text = rect1.ToString();
Graphics g = panel1.CreateGraphics();
x = (rect1.Width - 2) / 20 + 1;
y = (rect1.Height - 2) / 20 + 1;
if (e.Location.X == 0 || e.Location.Y == 0 || e.Location.X < 2 || e.Location.Y < 2)
{
x = 0;
y = 0;
}
if (x > 8)
x = 8;
if (y > 7)
y = 7;
labelMsg.Text = string.Format("{0} x {1}", x, y);
for (int i = 0; i < 8; i++)
{
for (int j = 0; j < 7; j++)
{
Rectangle rect2 = new Rectangle(1 + 1 + 20 * i, 1 + 1 + j * 20, 17, 17);
Brush brush1 = new SolidBrush(Color.White);
if (rect1.IntersectsWith(rect2))
brush1 = new SolidBrush(SystemColors.Highlight);
g.FillRectangle(brush1, rect2);
}
}
g.Dispose();
}
示例7: Main
static void Main(string[] args)
{
int bufSize = 256;
StringBuilder sb = new StringBuilder(bufSize);
Rectangle rect = new Rectangle(0, 0, 100, 100);
if (SetNHW32())
{
{
for (;;)
{
int i = 1;
int j = 0;
Point cursorPoint = new Point();
GetCursorPos(ref cursorPoint);
BL_SetFlag32((uint)GetWordFlag.enable, IntPtr.Zero, cursorPoint.X, cursorPoint.Y);
Thread.Sleep(1000);
BL_GetText32(sb, bufSize, ref rect);
System.Console.WriteLine(sb.ToString() + " " + rect.ToString() + " " + cursorPoint.ToString());
}
}
}
}
示例8: DrawSubItem
/// <summary>
/// Draw Sub Item (Cell) at location specified
/// </summary>
/// <param name="graphicsSubItem"></param>
/// <param name="rectSubItem"></param>
/// <param name="item"></param>
/// <param name="subItem"></param>
/// <param name="nColumn"></param>
public virtual void DrawSubItem( Graphics graphicsSubItem, Rectangle rectSubItem, GLItem item, GLSubItem subItem, int nColumn )
{
DW("DrawSubItem");
// precheck to make sure this is big enough for the things we want to do inside it
Rectangle subControlRect = new Rectangle( rectSubItem.X, rectSubItem.Y, rectSubItem.Width, rectSubItem.Height );
if ( ( subItem.Control != null ) && (!subItem.ForceText ) )
{ // custom embedded control here
Control control = subItem.Control;
if ( control.Parent != this ) // *** CRUCIAL *** this makes sure the parent is the list control
control.Parent = this;
// Rectangle subrc = new Rectangle(
// subControlRect.X+this.CellPaddingSize,
// subControlRect.Y+this.CellPaddingSize,
// subControlRect.Width-this.CellPaddingSize*2,
// subControlRect.Height-this.CellPaddingSize*2 );
Rectangle subrc = new Rectangle(
subControlRect.X,
subControlRect.Y+1,
subControlRect.Width,
subControlRect.Height-1 );
Type tp = control.GetType();
PropertyInfo pi = control.GetType().GetProperty( "PreferredHeight" );
if ( pi != null )
{
int PreferredHeight = (int)pi.GetValue( control, null );
if ( ( (PreferredHeight + this.CellPaddingSize*2)> this.ItemHeight ) && AutoHeight )
this.ItemHeight = PreferredHeight + this.CellPaddingSize*2;
subrc.Y = subControlRect.Y + ((subControlRect.Height - PreferredHeight)/2);
}
NewLiveControls.Add( control ); // put it in the new list, remove from old list
if ( LiveControls.Contains( control ) ) // make sure its in the old list first
{
LiveControls.Remove( control ); // remove it from list so it doesn't get put down
}
if ( control.Bounds.ToString() != subrc.ToString() )
control.Bounds = subrc; // this will force an invalidation
if ( control.Visible != true )
control.Visible = true;
}
else // not control based
{
// if the sub item color is not the same as the back color fo the control, AND the item is not selected, then color this sub item background
if ( ( subItem.BackColor.ToArgb() != this.BackColor.ToArgb() ) && (!item.Selected) && ( subItem.BackColor != Color.White ) )
{
SolidBrush bbrush = new SolidBrush( subItem.BackColor );
graphicsSubItem.FillRectangle( bbrush, rectSubItem );
bbrush.Dispose();
}
// do we need checkboxes in this column or not?
if ( this.Columns[ nColumn ].CheckBoxes )
rectSubItem = DrawCheckBox( graphicsSubItem, rectSubItem, subItem.Checked );
// if there is an image, this routine will RETURN with exactly the space left for everything else after the image is drawn (or not drawn due to lack of space)
if ( (subItem.ImageIndex > -1) && (ImageList != null) && (subItem.ImageIndex < this.ImageList.Images.Count) )
rectSubItem = DrawCellGraphic( graphicsSubItem, rectSubItem, this.ImageList.Images[ subItem.ImageIndex ], subItem.ImageAlignment );
// deal with text color in a box on whether it is selected or not
Color textColor;
if ( item.Selected && this.Selectable )
textColor = this.SelectedTextColor;
else
{
textColor = this.ForeColor;
if ( item.ForeColor.ToArgb() != this.ForeColor.ToArgb() )
textColor = item.ForeColor;
else if ( subItem.ForeColor.ToArgb() != this.ForeColor.ToArgb() )
textColor = subItem.ForeColor;
}
DrawCellText( graphicsSubItem, rectSubItem, subItem.Text, Columns[nColumn].TextAlignment, textColor, item.Selected, ItemWordWrap );
subItem.LastCellRect = rectSubItem; // important to ONLY catch the area where the text is drawn
}
}
示例9: CaptureWindowWithDWM
/// <summary>
/// Make a full-size thumbnail of the captured window on a new topmost form, and capture
/// this new form with a black and then white background. Then compute the transparency by
/// difference between the black and white versions.
/// This method has these advantages:
/// - the full form is captured even if it is obscured on the Windows desktop
/// - there is no problem with unpredictable Z-order anymore (the background and
/// the window to capture are drawn on the same window)
/// </summary>
/// <param name="handle">handle of the window to capture</param>
/// <param name="windowRect">the bounds of the window</param>
/// <param name="redBGImage">the window captured with a red background</param>
/// <param name="captureRedBGImage">whether to do the capture of the window with a red background</param>
/// <returns>the captured window image</returns>
private static Image CaptureWindowWithDWM(IntPtr handle, Rectangle windowRect, out Bitmap redBGImage, Color backColor)
{
Image windowImage = null;
redBGImage = null;
if (backColor != Color.White)
{
backColor = Color.FromArgb(255, backColor.R, backColor.G, backColor.B);
}
using (Form form = new Form())
{
form.StartPosition = FormStartPosition.Manual;
form.FormBorderStyle = FormBorderStyle.None;
form.ShowInTaskbar = false;
form.BackColor = backColor;
form.TopMost = true;
form.Bounds = CaptureHelpers.GetWindowRectangle(handle, false);
IntPtr thumb;
NativeMethods.DwmRegisterThumbnail(form.Handle, handle, out thumb);
SIZE size;
NativeMethods.DwmQueryThumbnailSourceSize(thumb, out size);
#if DEBUG
DebugHelper.WriteLine("Rectangle Size: " + windowRect.ToString());
DebugHelper.WriteLine("Window Size: " + size.ToString());
#endif
if (size.Width <= 0 || size.Height <= 0)
{
return null;
}
DWM_THUMBNAIL_PROPERTIES props = new DWM_THUMBNAIL_PROPERTIES();
props.dwFlags = NativeMethods.DWM_TNP_VISIBLE | NativeMethods.DWM_TNP_RECTDESTINATION | NativeMethods.DWM_TNP_OPACITY;
props.fVisible = true;
props.opacity = (byte)255;
props.rcDestination = new RECT(0, 0, size.Width, size.Height);
NativeMethods.DwmUpdateThumbnailProperties(thumb, ref props);
form.Show();
System.Threading.Thread.Sleep(250);
if (form.BackColor != Color.White)
{
// no need for transparency; user has requested custom background color
NativeMethods.ActivateWindowRepeat(form.Handle, 250);
windowImage = Screenshot.CaptureRectangleNative(windowRect) as Bitmap;
}
else if (form.BackColor == Color.White)
{
// transparent capture
NativeMethods.ActivateWindowRepeat(handle, 250);
Bitmap whiteBGImage = Screenshot.CaptureRectangleNative(windowRect) as Bitmap;
form.BackColor = Color.Black;
form.Refresh();
NativeMethods.ActivateWindowRepeat(handle, 250);
Bitmap blackBGImage = Screenshot.CaptureRectangleNative(windowRect) as Bitmap;
// Capture rounded corners with except for Windows 8
if (ZAppHelper.IsWindows8())
{
form.BackColor = Color.Red;
form.Refresh();
NativeMethods.ActivateWindowRepeat(handle, 250);
redBGImage = Screenshot.CaptureRectangleNative(windowRect) as Bitmap;
}
form.BackColor = Color.White;
form.Refresh();
NativeMethods.ActivateWindowRepeat(handle, 250);
Bitmap whiteBGImage2 = Screenshot.CaptureRectangleNative(windowRect) as Bitmap;
// Don't do transparency calculation if an animated picture is detected
if (whiteBGImage.AreBitmapsEqual(whiteBGImage2))
{
windowImage = HelpersLib.GraphicsHelper.Core.ComputeOriginal(whiteBGImage, blackBGImage);
}
else
{
DebugHelper.WriteLine("Detected animated image => cannot compute transparency");
form.Close();
//.........这里部分代码省略.........
示例10: SelectRectangle
private void SelectRectangle()
{
WindowState = FormWindowState.Minimized;
try
{
Thread.Sleep(250);
Rectangle rect;
if (SurfaceForm.SelectRegion(out rect))
{
selectedRectangle = rect;
lblSelectedRectangle.Text = selectedRectangle.ToString();
}
}
finally
{
this.ForceActivate();
}
}
示例11: GetGrayscaleBitmap
/*
* GetGrayscaleBitmap
*/
/// <summary>
/// Converts the specified <see cref="Bitmap"/> to grayscale image.
/// </summary>
/// <exception cref="T:System.ArgumentNullException">
/// <paramref name="sourceBitmap"/> is <see langword="null"/>.
/// </exception>
public static Bitmap GetGrayscaleBitmap(Bitmap sourceBitmap)
{
if (sourceBitmap == null)
{
throw new ArgumentNullException("bmp");
}
Bitmap bufferBmp = new Bitmap(sourceBitmap);
Rectangle bufferBmpRectangle = new Rectangle(0, 0, bufferBmp.Width, bufferBmp.Height);
ImageLockMode imgLockMode = ImageLockMode.ReadWrite;
PixelFormat pixelFormat = PixelFormat.Format32bppArgb;
if (_infoEnabled)
{
Trace.TraceInformation("bufferBmpRectangle = {0}", bufferBmpRectangle.ToString());
}
BitmapData bmpData = null;
try
{
bmpData = bufferBmp.LockBits(bufferBmpRectangle, imgLockMode, pixelFormat);
}
catch (Exception e)
{
if (_errorEnabled)
{
Trace.TraceError("Error occured while bufferBmp.LockBits operation: {0}", e.Message);
}
return null;
}
unsafe
{
uint* scan0 = (uint*)bmpData.Scan0;
for (int height = 0; height < bufferBmp.Height; height++)
{
for (int width = 0; width < bufferBmp.Width; width++)
{
int block1 = (bmpData.Stride * height) / 4;
uint block2 = scan0[block1 + width];
uint block3 = (block2 >> 0x10) & 0xff;
uint block4 = (block2 >> 8) & 0xff;
uint block5 = block2 & 0xff;
uint block6 = (block3 + block4 + block5) / 3;
scan0[block1 + width] = ((block6 << 0x10) + (block6 << 8)) + block6;
}
}
}
try
{
bufferBmp.UnlockBits(bmpData);
}
catch (Exception e)
{
if (_errorEnabled)
{
Trace.TraceError("Error occured while buffer.UnlockBits operation: {0}", e.Message);
}
return null;
}
return bufferBmp;
}
示例12: OnPaint
protected override void OnPaint(PaintEventArgs pe) {
Debug.WriteLineIf(CompModSwitches.DebugGridView.TraceVerbose, "PropertyGridView:OnPaint");
Debug.WriteLineIf(GridViewDebugPaint.TraceVerbose, "On paint called. Rect=" + pe.ClipRectangle.ToString());
Graphics g = pe.Graphics;
int yPos = 0;
int startRow = 0;
int endRow = visibleRows - 1;
Rectangle clipRect = pe.ClipRectangle;
// give ourselves a little breathing room to account for lines, etc., as well
// as the entries themselves.
//
clipRect.Inflate(0,2);
try {
Size sizeWindow = this.Size;
// figure out what rows we're painting
Point posStart = FindPosition(clipRect.X, clipRect.Y);
Point posEnd = FindPosition(clipRect.X, clipRect.Y + clipRect.Height);
if (posStart != InvalidPosition) {
startRow = Math.Max(0,posStart.Y);
}
if (posEnd != InvalidPosition) {
endRow = posEnd.Y;
}
int cPropsVisible = Math.Min(totalProps - GetScrollOffset(),1+visibleRows);
#if DEBUG
GridEntry debugIPEStart = GetGridEntryFromRow(startRow);
GridEntry debugIPEEnd = GetGridEntryFromRow(endRow);
string startName = debugIPEStart == null ? null : debugIPEStart.PropertyLabel;
if (startName == null) {
startName = "(null)";
}
string endName = debugIPEEnd == null ? null : debugIPEEnd.PropertyLabel;
if (endName == null) {
endName = "(null)";
}
#endif
SetFlag(FlagNeedsRefresh, false);
//SetConstants();
Size size = this.GetOurSize();
Point loc = this.ptOurLocation;
if (GetGridEntryFromRow(cPropsVisible-1) == null) {
cPropsVisible--;
}
// if we actually have some properties, then start drawing the grid
//
if (totalProps > 0) {
// draw splitter
cPropsVisible = Math.Min(cPropsVisible, endRow+1);
Debug.WriteLineIf(GridViewDebugPaint.TraceVerbose, "Drawing splitter");
Pen splitterPen = new Pen(ownerGrid.LineColor, GetSplitterWidth());
splitterPen.DashStyle = DashStyle.Solid;
g.DrawLine(splitterPen, labelWidth,loc.Y,labelWidth, (cPropsVisible)*(RowHeight+1)+loc.Y);
splitterPen.Dispose();
// draw lines.
Debug.WriteLineIf(GridViewDebugPaint.TraceVerbose, "Drawing lines");
Pen linePen = new Pen(g.GetNearestColor(ownerGrid.LineColor));
int cHeightCurRow = 0;
int cLineEnd = loc.X + size.Width;
int cLineStart = loc.X;
// draw values.
int totalWidth = GetTotalWidth() + 1;
//g.TextColor = ownerGrid.TextColor;
// draw labels. set clip rect.
for (int i = startRow; i < cPropsVisible; i++) {
try {
// draw the line
cHeightCurRow = (i)*(RowHeight+1) + loc.Y;
g.DrawLine(linePen, cLineStart,cHeightCurRow,cLineEnd,cHeightCurRow);
// draw the value
DrawValueEntry(g,i, ref clipRect);
// draw the label
Rectangle rect = GetRectangle(i,ROWLABEL);
yPos = rect.Y + rect.Height;
DrawLabel(g,i, rect, (i==selectedRow),false, ref clipRect);
if (i == selectedRow) {
Edit.Invalidate();
}
//.........这里部分代码省略.........
示例13: SelectHandle
private void SelectHandle()
{
WindowState = FormWindowState.Minimized;
bool capturing = false;
try
{
Thread.Sleep(250);
SimpleWindowInfo simpleWindowInfo = GetWindowInfo();
if (simpleWindowInfo != null)
{
selectedWindow = new WindowInfo(simpleWindowInfo.Handle);
lblControlText.Text = selectedWindow.ClassName ?? string.Empty;
selectedRectangle = simpleWindowInfo.Rectangle;
lblSelectedRectangle.Text = selectedRectangle.ToString();
btnSelectRectangle.Enabled = btnCapture.Enabled = true;
if (Options.StartCaptureAutomatically)
{
capturing = true;
StartCapture();
}
}
else
{
btnCapture.Enabled = false;
}
}
finally
{
if (!capturing) this.ForceActivate();
}
}
示例14: SetBoundsCore
protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
{
bool skipMessage = false;
Rectangle newBounds = new Rectangle(x, y, width, height);
if (GUIGraphicsContext._useScreenSelector && isMaximized)
{
if (!newBounds.Equals(GUIGraphicsContext.currentScreen.Bounds))
{
skipMessage = true;
}
}
if (skipMessage)
{
Log.Info("d3dapp: Screenselector: skipped SetBoundsCore {0} does not match {1}", newBounds.ToString(),
GUIGraphicsContext.currentScreen.Bounds.ToString());
}
else
{
base.SetBoundsCore(x, y, width, height, specified);
}
}
示例15: InvalidateEventsOrder
public void InvalidateEventsOrder ()
{
Rectangle rect = new Rectangle (new Point (0,0), new Size (2, 2));
Form myform = new Form ();
myform.ShowInTaskbar = false;
myform.Visible = true;
MyLabelInvalidate l = new MyLabelInvalidate ();
myform.Controls.Add (l);
l.TextAlign = ContentAlignment.TopRight;
string [] EventsWanted = {
"OnHandleCreated",
"OnBindingContextChanged",
"OnBindingContextChanged",
"OnInvalidated,{X=0,Y=0,Width="+l.Size.Width+",Height="+l.Size.Height+"}",
"OnInvalidated," + rect.ToString ()
};
l.Invalidate (rect);
Assert.AreEqual (EventsWanted, ArrayListToString (l.Results));
myform.Dispose();
}