本文整理汇总了C#中System.Drawing.Region.MakeEmpty方法的典型用法代码示例。如果您正苦于以下问题:C# Region.MakeEmpty方法的具体用法?C# Region.MakeEmpty怎么用?C# Region.MakeEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Drawing.Region
的用法示例。
在下文中一共展示了Region.MakeEmpty方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsOnScreen
/// <summary>
/// Returns whether the given rectangle, in screen coordinates, is visible in any screen's
/// working area (the monitor's visible area minus task bars and docked windows)</summary>
/// <param name="rect">Rectangle</param>
/// <returns>Whether the given rectangle is visible</returns>
public static bool IsOnScreen(Rectangle rect)
{
using (Region region = new Region())
{
region.MakeEmpty();
foreach (Screen screen in Screen.AllScreens)
region.Union(screen.WorkingArea);
rect.Inflate(-Margin, -Margin);
return region.IsVisible(rect);
}
}
示例2: MainForm_Load
/// <summary>
/// Called when the form loads
/// </summary>
/// <param name="sender">what triggered the event</param>
/// <param name="e">event args</param>
private void MainForm_Load(object sender, EventArgs e)
{
// make cool shape
Region r = new Region();
GraphicsPath gp = new GraphicsPath();
gp.AddEllipse(new Rectangle(0, 0, this.Width, this.Height));
r.MakeEmpty();
r.Union(gp);
gp = new GraphicsPath();
gp.AddRectangle(new Rectangle(this.Width / 2, 0, this.Width / 2, this.Height / 2));
r.Union(gp);
this.Region = r;
}
示例3: CombineAreas
public Region CombineAreas()
{
Region region = new Region();
region.MakeEmpty();
foreach (Area area in Areas)
{
region.Union(area.Region);
}
region.Intersect(new Region(Crop.Bounds));
return region;
}
示例4: GetRegion
private Region GetRegion(Bitmap _img)
{
var rgn = new Region();
rgn.MakeEmpty();
var rc = new Rectangle(0, 0, 0, 0);
bool inimage = false;
for (int y = 0; y < _img.Height; y++)
{
for (int x = 0; x < _img.Width; x++)
{
if (!inimage)
{
// if pixel is not transparent
if (_img.GetPixel(x, y).A != 0)
{
inimage = true;
rc.X = x;
rc.Y = y;
rc.Height = 1;
}
}
else
{
// if pixel is transparent
if (_img.GetPixel(x, y).A == 0)
{
inimage = false;
rc.Width = x - rc.X;
rgn.Union(rc);
}
}
}
if (inimage)
{
inimage = false;
rc.Width = _img.Width - rc.X;
rgn.Union(rc);
}
}
return rgn;
}
示例5: BlockRegions
static BlockRegions()
{
int n = Constants.PROJ_WIDTH / 4;
WholeBlock = new Region();
WholeBlock.MakeEmpty();
for (int i = 0; i <= n; i++)
{
WholeBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i, i * 4 + 2, Constants.PROJ_HEIGHT - 2 * i));
}
WholeBlock.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH, Constants.PROJ_HEIGHT));
InnerBlock = new Region();
InnerBlock.MakeEmpty();
for (int i = 0; i <= n; i++)
{
InnerBlock.Union(new Rectangle(n * 2 - 1 - 2 * i, i + 1, i * 4 + 2, Constants.PROJ_HEIGHT - 2 - 2 * i));
}
InnerBlock.Intersect(new Rectangle(1, 1, Constants.PROJ_WIDTH - 2, Constants.PROJ_HEIGHT - 2));
OuterBorder = WholeBlock.Clone();
OuterBorder.Exclude(InnerBlock);
Top = InnerBlock.Clone();
Top.Translate(0, -Constants.BLOCK_HEIGHT);
Top.Intersect(InnerBlock);
Left = InnerBlock.Clone();
Left.Exclude(Top);
Top.Translate(0, 1);
Left.Exclude(Top);
Top.Translate(0, -1);
Right = Left.Clone();
Left.Intersect(new Rectangle(0, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
Right.Intersect(new Rectangle(Constants.PROJ_WIDTH / 2 + 1, 0, Constants.PROJ_WIDTH / 2, Constants.PROJ_HEIGHT));
InnerBorder = InnerBlock.Clone();
InnerBorder.Exclude(Top);
InnerBorder.Exclude(Left);
InnerBorder.Exclude(Right);
}
示例6: Region
public Region this[int c]
{
get {
if (this.cgrom[c] == null)
{
int C = c * charHeight;
Region r = new Region();
r.MakeEmpty();
for (int y = 0; y < charHeight; ++y)
{
byte row = this.cgrom_raw[C + y];
for (int x = 0; x < charWidth && row != 0; ++x)
{
if ((row & 0x80) == 0x80)
r.Union(new Rectangle(x, y, 1, 1));
row <<= 1;
}
}
this.cgrom[c] = r;
}
return this.cgrom[c];
}
}
示例7: OnMouseLeave
void OnMouseLeave (object sender, EventArgs e)
{
Region region_to_invalidate = new Region ();
region_to_invalidate.MakeEmpty ();
bool dirty = false;
if (ThemeEngine.Current.ScrollBarHasHoverArrowButtonStyle) {
region_to_invalidate.Union (first_arrow_area);
region_to_invalidate.Union (second_arrow_area);
dirty = true;
} else
if (ThemeEngine.Current.ScrollBarHasHotElementStyles)
if (first_button_entered) {
region_to_invalidate.Union (first_arrow_area);
dirty = true;
} else if (second_button_entered) {
region_to_invalidate.Union (second_arrow_area);
dirty = true;
}
if (ThemeEngine.Current.ScrollBarHasHotElementStyles)
if (thumb_entered) {
region_to_invalidate.Union (thumb_pos);
dirty = true;
}
first_button_entered = false;
second_button_entered = false;
thumb_entered = false;
if (dirty)
Invalidate (region_to_invalidate);
region_to_invalidate.Dispose ();
}
示例8: EmptyRegionWithInfiniteRegion
public void EmptyRegionWithInfiniteRegion ()
{
Region empty = new Region ();
empty.MakeEmpty ();
Assert.IsTrue (empty.IsEmpty (graphic), "IsEmpty");
Region region = new Region ();
Assert.IsTrue (region.IsInfinite (graphic), "IsInfinite");
region.Union (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Union-IsInfinite");
region.Xor (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Xor-IsInfinite");
region.Exclude (empty);
Assert.IsTrue (region.IsInfinite (graphic), "Exclude-IsInfinite");
region.Intersect (empty);
Assert.IsTrue (region.IsEmpty (graphic), "Intersect-IsEmpty");
region.MakeInfinite ();
region.Complement (empty);
Assert.IsTrue (region.IsEmpty (graphic), "Complement-IsEmpty");
}
示例9: getRegion
public Region getRegion()
{
GraphicsPath gp = new GraphicsPath();
gp.AddLine(origin, destination);
Region region = new Region();
int l = Math.Min(source.Bounds.Left, target.Bounds.Left);
int t = Math.Min(source.Bounds.Top, target.Bounds.Top);
int r = Math.Max(source.Bounds.Right, target.Bounds.Right);
int b = Math.Max(source.Bounds.Bottom, target.Bounds.Bottom);
Rectangle rect = new Rectangle(1, t, r-1, b-t);
region.MakeEmpty();
region.Union(rect);
return region;
}
示例10: FillRegionEmpty
void FillRegionEmpty(Graphics g)
{
Pen myPen = new Pen(Color.FromArgb(196, 0xC3, 0xC9, 0xCF), (float)0.6);
SolidBrush myBrush = new SolidBrush(Color.FromArgb(127, 0xDD, 0xDD, 0xF0));
// Create the first rectangle and draw it to the screen in myPen color.
g.DrawRectangle(myPen, regionRect1);
// Create a region using the first rectangle.
Region myRegion = new Region(regionRect1);
myRegion.MakeEmpty ();
// Fill the region which basically clears the screen to the background color.
// Take a look at the initialize method of DrawingView.
// This may set the rectangle to Black depending on the context
// passed. On a NSView set WantsLayers and the Layer Background color.
g.FillRegion(myBrush, myRegion);
title = "FillEmptyRegion";
}
示例11: SetDataLabelsVisible
public void SetDataLabelsVisible( bool visible )
{
// set direct references
ZedGraph.GraphPane pane = zedGraphControl1.GraphPane;
ZedGraph.Axis xAxis = pane.XAxis;
ZedGraph.Axis yAxis = pane.YAxis;
if( CurrentGraphItem == null )
return;
//zedGraphControl1.GraphPane.GraphObjList.Clear();
foreach( ZedGraph.GraphObj dataLabel in dataLabels )
zedGraphControl1.GraphPane.GraphObjList.Remove( dataLabel );
if( visible )
{
if( CurrentGraphItem.IsChromatogram )
{
if( !( ChromatogramAnnotationSettings.ShowPointTimes ||
ChromatogramAnnotationSettings.ShowPointIntensities ||
ChromatogramAnnotationSettings.ShowUnmatchedAnnotations ||
ChromatogramAnnotationSettings.ShowMatchedAnnotations ) )
return;
} else
{
if( !( ScanAnnotationSettings.ShowPointMZs ||
ScanAnnotationSettings.ShowPointIntensities ||
ScanAnnotationSettings.ShowUnmatchedAnnotations ||
ScanAnnotationSettings.ShowMatchedAnnotations ) )
return;
}
yAxis.Scale.MinAuto = false;
yAxis.Scale.Min = 0;
// setup axes scales to enable the Transform method
xAxis.Scale.SetupScaleData( pane, xAxis );
yAxis.Scale.SetupScaleData( pane, yAxis );
Graphics g = zedGraphControl1.CreateGraphics();
System.Drawing.Bitmap gmap;
if( pane.Chart.Rect.Width > 0 && pane.Chart.Rect.Height > 0 )
{
try
{
//pane.Draw( g );
pane.CurveList.Draw( g, pane, 1.0f );
gmap = new Bitmap( Convert.ToInt32( pane.Rect.Width ), Convert.ToInt32( pane.Rect.Height ) );
zedGraphControl1.DrawToBitmap( gmap, Rectangle.Round( pane.Rect ) );
} catch
{
return;
}
} else
return;
Region textBoundsRegion;
Region chartRegion = new Region( pane.Chart.Rect );
Region clipRegion = new Region();
clipRegion.MakeEmpty();
g.SetClip( zedGraphControl1.MasterPane.Rect, CombineMode.Replace );
g.SetClip( chartRegion, CombineMode.Exclude );
/*Bitmap clipBmp = new Bitmap( Convert.ToInt32( pane.Rect.Width ), Convert.ToInt32( pane.Rect.Height ) );
Graphics clipG = Graphics.FromImage( clipBmp );
clipG.Clear( Color.White );
clipG.FillRegion( new SolidBrush( Color.Black ), g.Clip );
clipBmp.Save( "C:\\clip.bmp" );*/
PointDataMap<SeemsPointAnnotation> matchedAnnotations = new PointDataMap<SeemsPointAnnotation>();
// add precursor label(s) for tandem mass spectra
if( CurrentGraphItem.IsMassSpectrum )
{
MassSpectrum scanItem = (MassSpectrum) CurrentGraphItem;
pwiz.CLI.msdata.PrecursorList precursorList = scanItem.Element.spectrumDescription.precursors;
for( int i = 0; i < precursorList.Count; ++i )
{
pwiz.CLI.msdata.Precursor precursor = precursorList[i];
pwiz.CLI.msdata.SelectedIonList selectedIons = precursor.selectedIons;
if( selectedIons.Count == 0 )
continue;
double precursorMz = (double) selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_m_z ).value;
pwiz.CLI.msdata.CVParam precursorChargeParam = selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_charge_state );
int precursorCharge = 0;
if( precursorChargeParam.cvid != pwiz.CLI.msdata.CVID.CVID_Unknown )
precursorCharge = (int) selectedIons[0].cvParam( pwiz.CLI.msdata.CVID.MS_charge_state ).value;
float stickLength = ( yAxis.MajorTic.Size * 5 ) / pane.Chart.Rect.Height;
ZedGraph.LineObj stickOverlay = new ZedGraph.LineObj( precursorMz, 1, precursorMz, 1 + stickLength );
stickOverlay.Location.CoordinateFrame = ZedGraph.CoordType.XScaleYChartFraction;
stickOverlay.Line.Width = 3;
stickOverlay.Line.Style = DashStyle.Dot;
stickOverlay.Line.Color = Color.Green;
pane.GraphObjList.Add( stickOverlay );
dataLabels.Add( stickOverlay );
// Create a text label from the X data value
string precursorLabel;
if( precursorCharge > 0 )
//.........这里部分代码省略.........
示例12: MakeTransparent
/// <summary>
/// Makes the current <see cref="RichTextBoxLineNumbers"/> transparent
/// by matching <see cref="Region"/> to the given <see cref="GraphicsPath"/>s.
/// </summary>
/// <param name="graphicPaths"></param>
private void MakeTransparent(IEnumerable<GraphicsPath> graphicPaths)
{
var region = new Region(ClientRectangle);
region.MakeEmpty();
foreach (var path in graphicPaths)
region.Union(path);
Region = region;
}
示例13: OnPaint
//.........这里部分代码省略.........
// --- BorderLines
Point[] zBorderLines_Points = {
new Point(zP_Left.X, zP_Left.Y),
new Point(zP_Right.X, zP_Left.Y),
new Point(zP_Right.X, zP_Right.Y),
new Point(zP_Left.X, zP_Right.Y),
new Point(zP_Left.X, zP_Left.Y)
};
if (zBorderLines_Show == true) {
zPen = new Pen(zBorderLines_Color, zBorderLines_Thickness);
zPen.DashStyle = zBorderLines_Style;
e.Graphics.DrawLines(zPen, zBorderLines_Points);
zGP_BorderLines.AddLines(zBorderLines_Points);
zGP_BorderLines.CloseFigure();
// BorderThickness and Style for SeeThroughMode
zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
zGP_BorderLines.Widen(zPen);
}
// --- MarginLines
if (zMarginLines_Show == true && zMarginLines_Side > LineNumberDockSide.None) {
zP_Left = new Point((int)(-zMarginLines_Thickness), (int)(-zMarginLines_Thickness));
zP_Right = new Point((int)(this.Width + zMarginLines_Thickness), (int)(this.Height + zMarginLines_Thickness));
zPen = new Pen(zMarginLines_Color, zMarginLines_Thickness);
zPen.DashStyle = zMarginLines_Style;
if (zMarginLines_Side == LineNumberDockSide.Left | zMarginLines_Side == LineNumberDockSide.Height) {
e.Graphics.DrawLine(zPen, new Point(
(int)(Math.Floor(zMarginLines_Thickness / 2)), 0),
new Point(
(int)(Math.Floor(zMarginLines_Thickness / 2)),
this.Height - 1)
);
zP_Left = new Point(
(int)(Math.Ceiling(zMarginLines_Thickness / 2)),
(int)(-zMarginLines_Thickness));
}
if (zMarginLines_Side == LineNumberDockSide.Right | zMarginLines_Side == LineNumberDockSide.Height) {
e.Graphics.DrawLine(zPen, new Point(
(int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)), 0),
new Point(
(int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)),
(int)(this.Height - 1))
);
zP_Right = new Point(
(int)(this.Width - Math.Ceiling(zMarginLines_Thickness / 2)),
(int)(this.Height + zMarginLines_Thickness)
);
}
// GraphicsPath for the MarginLines(s):
// MarginLines(s) are drawn as a rectangle connecting the zP_Left and zP_Right points, which are either inside or
// outside of sight, depending on whether the MarginLines at that side is visible. zP_Left: TopLeft and ZP_Right: BottomRight
zGP_MarginLines.AddRectangle(new Rectangle(zP_Left, new Size(zP_Right.X - zP_Left.X, zP_Right.Y - zP_Left.Y)));
zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
zGP_MarginLines.Widen(zPen);
}
// ----------------------------------------------
// --- SeeThroughMode
// combine all the GraphicsPaths (= zGP_... ) and set them as the region for the control.
if (zSeeThroughMode == true) {
zRegion.MakeEmpty();
zRegion.Union(zGP_BorderLines);
zRegion.Union(zGP_MarginLines);
zRegion.Union(zGP_GridLines);
zRegion.Union(zGP_LineNumbers);
}
// --- Region
if (zRegion.GetBounds(e.Graphics).IsEmpty == true) {
// Note: If the control is in a condition that would show it as empty, then a border-region is still drawn regardless of it's borders on/off state.
// This is added to make sure that the bounds of the control are never lost (it would remain empty if this was not done).
zGP_BorderLines.AddLines(zBorderLines_Points);
zGP_BorderLines.CloseFigure();
zPen = new Pen(zBorderLines_Color, 1);
zPen.DashStyle = System.Drawing.Drawing2D.DashStyle.Solid;
zGP_BorderLines.Widen(zPen);
zRegion = new Region(zGP_BorderLines);
}
this.Region = zRegion;
// ----------------------------------------------
// --- Memory CleanUp
if (zPen != null)
zPen.Dispose();
if (zBrush != null)
zPen.Dispose();
if (zRegion != null)
zRegion.Dispose();
if (zGP_GridLines != null)
zGP_GridLines.Dispose();
if (zGP_BorderLines != null)
zGP_BorderLines.Dispose();
if (zGP_MarginLines != null)
zGP_MarginLines.Dispose();
if (zGP_LineNumbers != null)
zGP_LineNumbers.Dispose();
}
示例14: OnMouseMove
protected override void OnMouseMove (MouseEventArgs e)
{
ButtonState before, after;
before = ButtonState.Normal;
if ((mouse_pressed == 1) && top_button_rect.Contains(mouse_x, mouse_y))
before = ButtonState.Pushed;
if ((mouse_pressed == 2) && bottom_button_rect.Contains(mouse_x, mouse_y))
before = ButtonState.Pushed;
mouse_x = e.X;
mouse_y = e.Y;
after = ButtonState.Normal;
if ((mouse_pressed == 1) && top_button_rect.Contains(mouse_x, mouse_y))
after = ButtonState.Pushed;
if ((mouse_pressed == 2) && bottom_button_rect.Contains(mouse_x, mouse_y))
after = ButtonState.Pushed;
bool new_top_button_entered = top_button_rect.Contains (e.Location);
bool new_bottom_button_entered = bottom_button_rect.Contains (e.Location);
if (before != after) {
if (after == ButtonState.Pushed) {
tmrRepeat.Enabled = true;
repeat_counter = 0;
repeat_delay = InitialRepeatDelay;
// fire off one right now too for good luck
if (mouse_pressed == 1)
owner.UpButton();
if (mouse_pressed == 2)
owner.DownButton();
}
else
tmrRepeat.Enabled = false;
top_button_entered = new_top_button_entered;
bottom_button_entered = new_bottom_button_entered;
Refresh ();
} else {
if (ThemeEngine.Current.UpDownBaseHasHotButtonStyle) {
Region area_to_invalidate = new Region ();
bool dirty = false;
area_to_invalidate.MakeEmpty ();
if (top_button_entered != new_top_button_entered) {
top_button_entered = new_top_button_entered;
area_to_invalidate.Union (top_button_rect);
dirty = true;
}
if (bottom_button_entered != new_bottom_button_entered) {
bottom_button_entered = new_bottom_button_entered;
area_to_invalidate.Union (bottom_button_rect);
dirty = true;
}
if (dirty)
Invalidate (area_to_invalidate);
area_to_invalidate.Dispose ();
} else {
top_button_entered = new_top_button_entered;
bottom_button_entered = new_bottom_button_entered;
}
}
}
示例15: CreateRegionFromBitmap
//Format24bppRgb・Format32bppRgb・Format32bppArgb
//http://d.hatena.ne.jp/aharisu/20090523/1243077727
//コードは上記より拝借
public Region CreateRegionFromBitmap(Bitmap bitmap)
{
if (!(bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format24bppRgb ||
bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb ||
bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppRgb))
return null;// 24bitか32bit以外は無理
//ここの変数もっとまともな名前つけたい
int channels = Image.GetPixelFormatSize(bitmap.PixelFormat) / 8;
int offset = 0;
int count = channels;
if (bitmap.PixelFormat == System.Drawing.Imaging.PixelFormat.Format32bppArgb)
{//Format32bppArgbの場合はα値のみを確認する
count = 1;
offset = 3;
}
//ビットマップから生データを取得
Rectangle rectBitmap = new Rectangle(0, 0, bitmap.Width, bitmap.Height);
System.Drawing.Imaging.BitmapData data = bitmap.LockBits(rectBitmap,
System.Drawing.Imaging.ImageLockMode.ReadOnly, bitmap.PixelFormat);
byte[] values = new byte[data.Height * data.Stride];
System.Runtime.InteropServices.Marshal.Copy(data.Scan0, values, 0, data.Height * data.Stride);
bitmap.UnlockBits(data);
//透明にする色を取得
byte[] transparent = new byte[count];
if (count == 1)
transparent[0] = 0;
else
{
for (int i = 0; i < count; ++i)
transparent[i] = values[i];
}
Region region = new Region();
region.MakeEmpty();
Rectangle rect = new Rectangle();
for (int y = 0; y < data.Height; ++y)
{
int offsetY = y * data.Stride;
for (int x = 0; x < data.Width; ++x)
{
for (int c = 0; c < count; ++c)
{
if (transparent[c] != values[offsetY + x * channels + c + offset])
{//透過色ではない
rect.X = x;//透過色ではないスタート地点を保存
for (++x; x < data.Width; ++x)
{
for (c = 0; c < count; ++c)
{
if (transparent[c] != values[offsetY + x * channels + c + offset])
goto CONTINUE; //透過色ではないので続ける
}
break; //次の透過色を見つけたので脱出
CONTINUE:
;
}
rect.Width = x - rect.X;
rect.Y = y;
rect.Height = 1;
//透過色でない部分をリージョンに追加する
region.Union(rect);
break;
}
}
}
}
return region;
}