1

Please refer to the following image:

enter image description here

I want to exclude the area outside the orange border line.

How to remove the mentioned area?

or

how to set transparent the mentioned area, so that the control will be rendered with only marked region.

Could anyone please update me on this?

Amal
  • 576
  • 1
  • 6
  • 26
  • You will ned to create a suitable GraphicsPath that follows your shape or maybe even subtract two circular regions from a Rectangluar one.. The principle it always the same: create a shapeed region and set the controls clipping to it! – TaW Apr 06 '17 at 07:44
  • `int h2 = yourCtl.Height / 2; GraphicsPath gp = new GraphicsPath(); gp.AddRectangle(new Rectangle(0,0, yourCtl.Width, yourCtl.Height)); GraphicsPath gp1 = new GraphicsPath(); gp1.AddEllipse(-h2, -h2, 2*h2, 2*h2); GraphicsPath gp2 = new GraphicsPath(); gp2.AddEllipse(-h2, h2, 2*h2, 2*h2); Region r1 = new Region(gp1); Region r2 = new Region(gp2); Region r = new Region(gp); r.Exclude(gp1); r.Exclude(gp2); yourCtl.Region = r;` – TaW Apr 06 '17 at 07:55
  • Hi @TaW, Is there any way apart from excluding the unwanted area from region? – Amal Apr 06 '17 at 08:58
  • No, that's the way to do it in Winforms. Some (many) controls support a BackgroundImage; if you create one with transparent parts the effect will be similar; you will have to set the Style to FlatStyle and make the Basckcolor transparent, too. But as the Region is still a rectangle so will the the focus be and then some.. – TaW Apr 06 '17 at 08:59
  • @TaW - Can we make the mentioned area as transparent and draw triangle alone? If so, how to achieve this? – Amal Apr 06 '17 at 09:02
  • Yes, you can do that in the Paint event; but again, the FocusRectangle will still cover the whole control, if it has one.. What control are we talking about? – TaW Apr 06 '17 at 09:06
  • @TaW - i have developed a control derived from Control and uses it as a ToolTip – Amal Apr 06 '17 at 09:09
  • How to make the mentioned area as transparent in Paint? – Amal Apr 06 '17 at 09:09
  • You should be able to set the Control's BackColor to Color.Transparent. Then code the OnPaint event: `protected override void OnPaint(PaintEventArgs e){...}` - I would still go for the Region, esp. if you want the tooltip to overlay other controls.. – TaW Apr 06 '17 at 09:12
  • @TaW - When i set BackColor as Transparent to the control i derived from Control, it throws "Control does not support transparent colors" exception – Amal Apr 06 '17 at 13:06
  • That is right. I had tested with a Button. For a more basic Control you need allow tranperency (or what passes for it in winforms..) See [here for an example](http://stackoverflow.com/questions/9358500/making-a-control-transparent) – TaW Apr 06 '17 at 13:17

0 Answers0