本文整理匯總了C#中System.Drawing.Region.Union方法的典型用法代碼示例。如果您正苦於以下問題:C# Region.Union方法的具體用法?C# Region.Union怎麽用?C# Region.Union使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Drawing.Region
的用法示例。
在下文中一共展示了Region.Union方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: 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;
}
示例2: OnPaint
protected override void OnPaint (PaintEventArgs pevent)
{
Console.WriteLine ("ourLabelTwoAreas pevents {0}, pos {1} - size {2}", pevent.ClipRectangle,
Location, Size);
Region reg = new Region (new Rectangle (20, 20, 10, 10));
reg.Union (new Rectangle (5, 5, 10, 10));
pevent.Graphics.Clip = reg;
pevent.Graphics.FillRectangle (Brushes.Red, pevent.ClipRectangle);
}
示例3: 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;
}
示例4: 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);
}
}
示例5: 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;
}
示例6: CreateRegion
public static void CreateRegion(Control control, Rectangle bounds, int radius, RoundStyle roundStyle)
{
using (GraphicsPath path = GraphicsPathHelper.CreatePath(bounds, radius, roundStyle, true))
{
Region region = new Region(path);
path.Widen(Pens.White);
region.Union(path);
if (control.Region != null)
{
control.Region.Dispose();
}
control.Region = region;
}
}
示例7: 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);
}
示例8: TestBounds
public void TestBounds()
{
Bitmap bmp = new Bitmap (600, 800);
Graphics dc = Graphics.FromImage (bmp);
Rectangle rect1, rect2;
Region rgn1, rgn2;
RectangleF bounds;
rect1 = new Rectangle (500, 30, 60, 80);
rect2 = new Rectangle (520, 40, 60, 80);
rgn1 = new Region(rect1);
rgn2 = new Region(rect2);
rgn1.Union(rgn2);
bounds = rgn1.GetBounds (dc);
Assert.AreEqual (500, bounds.X);
Assert.AreEqual (30, bounds.Y);
Assert.AreEqual (80, bounds.Width);
Assert.AreEqual (90, bounds.Height);
}
示例9: Tick
public void Tick()
{
System.Drawing.Region r = new System.Drawing.Region();
int living = 0;
var ruleset = ((RuleSet)cbRuleSet.SelectedItem);
for (int x = 0; x <= zellen.GetUpperBound(0); x++)
{
for (int y = 0; y <= zellen.GetUpperBound(1); y++)
{
zellen[x, y].Aenderung = ruleset.applyRuleset(zellen[x, y].Status, getLivingNeighbours(x, y));
}
}
for (int x = 0; x <= zellen.GetUpperBound(0); x++)
{
for (int y = 0; y <= zellen.GetUpperBound(1); y++)
{
if (zellen[x, y].Status != zellen[x, y].Aenderung)
{
zellen[x, y].hasChanged = true;
zellen[x, y].Status = zellen[x, y].Aenderung;
r.Union(canvas.getRectangle(x, y));
}
living += zellen[x, y].Status == ZellenStatus.Lebt ? 1 : 0;
}
}
ticks++;
lblTicks.Text = ticks.ToString();
lblLivingCells.Text = living.ToString();
canvas.Invalidate(r);
if (cbLimit.Checked && ticks >= nupLimit.Value)
{
Stop();
}
if (cbEnableStats.Checked)
{
_stats.Add(new StatisticEntry(ticks, living));
}
}
示例10: DrawRegionOperations
private void DrawRegionOperations()
{
g = this.CreateGraphics();
// Создаем два прямоугольника
Rectangle rect1 = new Rectangle(100, 100, 120, 120);
Rectangle rect2 = new Rectangle(70, 70, 120, 120);
// Создаем два региона
Region rgn1 = new Region(rect1);
Region rgn2 = new Region(rect2);
// рисуем прямоугольники
g.DrawRectangle(Pens.Green, rect1);
g.DrawRectangle(Pens.Black, rect2);
// обработаем перечисление и вызовем соответствующий метод
switch (rgnOperation)
{
case RegionOperations.Union:
rgn1.Union(rgn2);
break;
case RegionOperations.Complement:
rgn1.Complement(rgn2);
break;
case RegionOperations.Intersect:
rgn1.Intersect(rgn2);
break;
case RegionOperations.Exclude:
rgn1.Exclude(rgn2);
break;
case RegionOperations.Xor:
rgn1.Xor(rgn2);
break;
default:
break;
}
// Рисуем регион
g.FillRegion(Brushes.Blue, rgn1);
g.Dispose();
}
示例11: DrawRegionOperation
void DrawRegionOperation()
{
g = this.CreateGraphics();
Rectangle rect1 = new Rectangle(100, 100, 120, 120);
Rectangle rect2 = new Rectangle(70, 70, 120, 120);
Region rgn1 = new Region(rect1);
Region rgn2 = new Region(rect2);
g.DrawRectangle(Pens.Blue, rect1);
g.DrawRectangle(Pens.Red, rect2);
switch(rgnOperation)
{
case RegionOperation.Union:
rgn1.Union(rgn2);
break;
case RegionOperation.Complement:
rgn1.Complement(rgn2);
break;
case RegionOperation.Intersect:
rgn1.Intersect(rgn2);
break;
case RegionOperation.Exclude:
rgn1.Exclude(rgn2);
break;
case RegionOperation.Xor:
rgn1.Xor(rgn2);
break;
default:
break;
}
g.FillRegion(Brushes.Tomato, rgn1);
g.Dispose();
}
示例12: 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];
}
}
示例13: 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 ();
}
示例14: OnMouseEnter
void OnMouseEnter (object sender, EventArgs e)
{
if (ThemeEngine.Current.ScrollBarHasHoverArrowButtonStyle) {
Region region_to_invalidate = new Region (first_arrow_area);
region_to_invalidate.Union (second_arrow_area);
Invalidate (region_to_invalidate);
}
}
示例15: TakeWorkflowSnapShot
internal static void TakeWorkflowSnapShot(WorkflowView workflowView, ViewPortData viewPortData)
{
Bitmap memoryBitmap = viewPortData.MemoryBitmap;
using (Graphics graphics = Graphics.FromImage(memoryBitmap))
{
graphics.SmoothingMode = SmoothingMode.HighQuality;
graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
using (PaintEventArgs args = new PaintEventArgs(graphics, viewPortData.LogicalViewPort))
{
workflowView.ActiveLayout.OnPaint(args, viewPortData);
}
Matrix matrix = new Matrix();
matrix.Scale(viewPortData.Scaling.Width, viewPortData.Scaling.Height, MatrixOrder.Prepend);
Point[] pts = new Point[] { viewPortData.LogicalViewPort.Location };
matrix.TransformPoints(pts);
matrix.Translate((float) (-pts[0].X + viewPortData.ShadowDepth.Width), (float) (-pts[0].Y + viewPortData.ShadowDepth.Height), MatrixOrder.Append);
graphics.Transform = matrix;
if (workflowView.RootDesigner != null)
{
using (Region region = new Region())
{
using (GraphicsPath path = ActivityDesignerPaint.GetDesignerPath(workflowView.RootDesigner, false))
{
Region clip = graphics.Clip;
region.MakeEmpty();
region.Union(path);
graphics.Clip = region;
AmbientTheme ambientTheme = WorkflowTheme.CurrentTheme.AmbientTheme;
graphics.FillRectangle(ambientTheme.BackgroundBrush, workflowView.RootDesigner.Bounds);
if (ambientTheme.ShowGrid)
{
ActivityDesignerPaint.DrawGrid(graphics, workflowView.RootDesigner.Bounds);
}
graphics.Clip = clip;
try
{
using (PaintEventArgs args2 = new PaintEventArgs(graphics, viewPortData.LogicalViewPort))
{
((IWorkflowDesignerMessageSink) workflowView.RootDesigner).OnPaint(args2, viewPortData.LogicalViewPort);
}
}
catch (Exception)
{
}
}
}
}
using (PaintEventArgs args3 = new PaintEventArgs(graphics, workflowView.RootDesigner.Bounds))
{
using (WorkflowMessageDispatchData data = new WorkflowMessageDispatchData(workflowView, EventArgs.Empty))
{
foreach (WorkflowDesignerMessageFilter filter in data.Filters)
{
try
{
if (((IWorkflowDesignerMessageSink) filter).OnPaint(args3, viewPortData.LogicalViewPort))
{
goto Label_0230;
}
}
catch (Exception)
{
}
}
}
}
Label_0230:
graphics.Transform = new Matrix();
if (!viewPortData.ShadowDepth.IsEmpty)
{
Bitmap image = new Bitmap(memoryBitmap);
using (Brush brush = new SolidBrush(Color.FromArgb(220, Color.White)))
{
graphics.FillRectangle(brush, new Rectangle(Point.Empty, new Size((memoryBitmap.Size.Width - viewPortData.ShadowDepth.Width) - 1, (memoryBitmap.Size.Height - viewPortData.ShadowDepth.Height) - 1)));
}
ImageAttributes imageAttr = new ImageAttributes();
imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Default);
imageAttr.SetColorKey(viewPortData.TransparentColor, viewPortData.TransparentColor, ColorAdjustType.Bitmap);
graphics.DrawImage(image, new Rectangle(-viewPortData.ShadowDepth.Width, -viewPortData.ShadowDepth.Height, memoryBitmap.Width, memoryBitmap.Height), 0, 0, memoryBitmap.Width, memoryBitmap.Height, GraphicsUnit.Pixel, imageAttr);
image.Dispose();
}
}
}