 |
|
 |
You can change the owner from Form to Control.
|
|
|
|
 |
|
 |
I tried to overlay text on the AxVLC player in the winForms. But it is not happening in the case of vlc player.
Can any one tell me how to overlay text on the Axvlc plugin Media player..........
Thank You!!!!!!
SIRIGINEEDI
|
|
|
|
 |
|
 |
I don't have any experience with the AxVLC control.
If it doesn't support a paint event, the overlay control will not be able to draw on it. The TextBox control has this problem, too.
Since you only want to display text, you might be able to put a label over it and set the label's BackColor property to Transparent (click on the label, then press F4 (properties) | BackColor | Web | Transparent).
|
|
|
|
 |
|
 |
Great concept, clean and very informative code!
|
|
|
|
 |
|
|
 |
|
 |
it's very useful,but his code has unnessary logic.not perfect
|
|
|
|
 |
|
 |
Hi!
Scrolling seems to make things messy. Auto scroll make scroll bars appear and they then draw over the overlay. Also if you scroll a panel the overlay will scroll along.
I'm no C# guru so I can't seem to find a nice way of solving it, could you please give it a try? Other than that it seems to work fine and from what I've found on google it looks like the nicest and most general solution to the problem.
Rikard
|
|
|
|
 |
|
 |
Call Refresh() each time you change the co-ordinates.
What I did:
On Form1 (from the demo code) I put a big picture inside an autosized PictureBox inside a small Panel and added an HScrollBar with the following handler:
private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
{
pictureBox3.Left = -hScrollBar1.Value;
pictureBox3.Top = -hScrollBar1.Value;
pictureBox3.Refresh();
}
I set it up so the red circle would draw over the Panel and the PictureBox.
When I moved the scroll bar, the graphical overlay updated with each change.
(Granted, there is a very slight, but noticeable, lag. I'll leave the solution to that problem for somebody with more free time than I have.)
My hScrollBar1_Scroll() handler, above, is being controlled by the user, but this fix should work regardless of how you are generating the coordinates.
Note 1: The GraphicalOverlayComponent will not draw over a scroll bar.
Note 2: I have NOT added my example code (above) to the downloadable demo code.
modified 5 Oct '11.
|
|
|
|
 |
|
 |
Specific working example with explaination
|
|
|
|
 |
|
 |
I have a number of shapes that need to be drawn over existing controls.
This is done dynamically at runtime, based on a configuration.
Currently, this works by drawing the required objects from the WinForm graphicalOverlay1_Paint(...) event...per the sample code.
We'd like to be able to dynamically create graphicalOverlay1 and class the code required to draw the shapes.
For example:
Say we have a WinForm, a Circle Class, a Square Class and the GraphicalOverlay Class.
The goal would be to dynamically create Graphical Overlay's for Circle and Square on WinForm...updating the object when any of the WinForm control objects fired their paint events.
|
|
|
|
 |
|
 |
The goal that you've described sounds straightforward, but your post doesn't actually ask a question that I can respond to.
I assume you're asking how to accomplish the goal.
Here is one way:
Add a file called ShapeClass.cs to the GraphicalOverlay demo project.
Put the following code in it:
using System.Drawing;
namespace CodeProject
{
public abstract class Shape
{
public Pen Pen { get; set; }
public Rectangle Bounds { get; set; }
public abstract void Draw(Graphics graphics);
public Shape(Rectangle bounds, Pen pen)
{
Bounds = bounds;
Pen = pen;
}
}
public class Square : Shape
{
public Square(Rectangle bounds, Pen pen)
: base(bounds, pen)
{
}
public override void Draw(Graphics graphics)
{
graphics.DrawRectangle(Pen, Bounds);
}
}
public class Circle : Shape
{
public Circle(Rectangle bounds, Pen pen)
: base(bounds, pen)
{
}
public override void Draw(Graphics graphics)
{
graphics.DrawEllipse(Pen, Bounds);
}
}
}
Replace the code that is currently in Form2.cs with this code:
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
namespace CodeProject
{
public partial class Form2 : Form
{
private List<Shape> shapeCollection = new List<Shape>
{
new Square(Rectangle.FromLTRB(10, 10, 60, 60), new Pen(Color.Red, 3)),
new Square(Rectangle.FromLTRB(20, 20, 80, 80), new Pen(Color.Green, 5)),
new Circle(Rectangle.FromLTRB(15, 15, 90, 90), new Pen(Color.Blue, 7))
};
public Form2()
{
InitializeComponent();
graphicalOverlay1.Owner = this;
}
private void graphicalOverlay1_Paint(object sender, PaintEventArgs e)
{
foreach (Shape shape in shapeCollection)
shape.Draw(e.Graphics);
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
Invalidate(true);
}
}
}
At runtime, you can add, modify, or remove circles and squares from the shapeCollection. Each time you have the collection configured the way you want it, call "Invalidate(true);" (as shown in the checkBox1_CheckedChanged() event handler) to cause the form to repaint.
|
|
|
|
 |
|
 |
RocketteScientist,
Excellent example and Great follow up.
Exactly what was needed.
Thanks Again,
BoilerProg
Errata (follow up) :
using System.Drawing.Drawing2D;
required to support Hatching functions in the code that follows in Form2.cs
|
|
|
|
 |
|
 |
I'm not 100% sure why my controls underneath weren't drawing correctly, but reverting the graphics transform after the overlay is done fixed the problem:
At the end of Control_Paint() added
if (control != form)
e.Graphics.TranslateTransform(location.X, location.Y);
The controls underneath mostly weren't rendering at all, but they were still displaying tooltips in the correct locations. They were UserControls with an overridden OnPaint() call.
If the graphical overlay caught the paint event before a control's OnPaint() got called, that would explain the symptoms.
|
|
|
|
 |
|
 |
Nice code, complicated problem, ugly and useless result!
|
|
|
|
 |
|
 |
I just sent revised versions of the two .zip files for this article.
The new version of the component handles hierarchical controls (containers) correctly.
It also handles dynamically added controls gracefully.
I also removed some unnecessary logic.
Apparently I can't just replace the .zip files on my own anymore.
I had to send them to Code Project via email and they will replace them for me.
So, I'm not sure how long it will take for them to appear in the article.
The new files were created with Microsoft Visual C# 2010 Express, so the .csproj files won't work with older versions of Visual Studio.
If you want to use Visual Studio 2008, create your own .csproj file and add all of the demo files to it.
Or, download Microsoft Visual C# 2010 Express. It's free.
|
|
|
|
 |
|
 |
Is it true that the GraphicalOverlay can't paint over a SplitContainer? Or is there a way to resolve this Problem?
|
|
|
|
 |
|
 |
I found the problem.
I was only painting the controls that were directly on the form.
The fix, below, will build a list of all of the controls in the hierarchy.
Delete the existing Owner property and paste all of this code in its place.
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public Form Owner
{
get { return form; }
set
{
if (value == null)
throw new ArgumentNullException();
if (form != null)
throw new InvalidOperationException();
form = value;
form.Resize += new EventHandler(Form_Resize);
ConnectPaintEventHandlers(form);
}
}
private void ConnectPaintEventHandlers(Control control)
{
control.Paint += new PaintEventHandler(Control_Paint);
foreach (Control child in control.Controls)
ConnectPaintEventHandlers(child);
}
|
|
|
|
 |
|
 |
There was more that needed fixing than just the bit I gave you in the previous answer.
I've given Code Project new versions of the component and the demo projects.
They should be available in a couple of days.
If you need them sooner, send me a private email and I'll send them to you directly.
Once you have the new version of the component, if you want to repaint the form, you'll need to call "Invalidate(true)".
For example:
private void TextBox_TextChanged(object sender, EventArgs e)
{
Invalidate(true);
}
|
|
|
|
 |
|
 |
Hi,
I have a form with text boxes where i can put the coordinates and the size parameters. When a button is clicked, the circle is painted.
Is there a way to achieve this with your code?
thanks,
Dramirak
|
|
|
|
 |
|
 |
I think this is what you're asking for... You will need to tie the TextChanged event from your text boxes to the TextBox_TextChanged event handler, below. Note, however, that because of the way Microsoft implemented the TextBox control, the GraphicalOverlay component can't draw over them.
public partial class Form1 : Form { private int xCenter = 0; private int yCenter = 0; private int radius = 0; public Form1() { InitializeComponent(); // Tell the graphical overlay that it belongs to this form. // This allows the component to transform the paint event's graphics object // and to respond when the form is resized. graphicalOverlay1.Owner = this; } private void graphicalOverlay1_Paint(object sender, PaintEventArgs e) { // This event will fire for the form and each control on the form. // The graphical overlay component will have already transformed the graphics object // to use the form's coordinate system, so no control-specific calculations are required. int.TryParse(radiusTextBox.Text, out radius); int.TryParse(xTextBox.Text, out xCenter); int.TryParse(yTextBox.Text, out yCenter); int x1 = xCenter - radius; int y1 = yCenter - radius; int x2 = xCenter + radius; int y2 = yCenter + radius; e.Graphics.DrawEllipse(Pens.Red, Rectangle.FromLTRB(x1, y1, x2, y2)); } private void TextBox_TextChanged(object sender, EventArgs e) { Invalidate(); } }
|
|
|
|
 |
|
 |
Of course, this worked fine, I did not understand the code at first. This is really cool. The fact that it don’t draw over the textbox is not an issue because I want the circle to be painted over a pictureBox and this is working well. Thanks, this is very cool code. I will include-it in my project and I’ll let you know when it is finished.
|
|
|
|
 |
|
 |
I started using your Graphical Overlay class, and its working out well, except for one thing:
I have nested controls. The class doesn't support these by default, so I manually added them at runtime. The problem is, it now draws two lines on the parent control, slightly offset from each other. I've taken a screenshot, but there is no image attachment option here, so I will attempt to illustrate it with ASCII art.
_______________________________________
00000000000000000000000011000000000000|
00______________000________________|00|
00|0000000000000|000|000001000000000|00|
00|0000000000000|000|000001000000000|00|
00|0000000000000|000|000001000000000|00|
00|0000000000000|000|000001000000000|00|
00|0000000000000|000|000001000000000|00|
The underscores represent the control borders, the 0s represent empty space (the posting engine here seems to truncate whitespaces, so I couldn't use those), and the 1s represent the line that it draws. As hopefully (I've never been good with ASCII art) you can see, it draws a line that is 100% correct. It also draws an extra line fragment in the parent control, offset by a few pixels, to the left of the correct line.
Any ideas?
|
|
|
|
 |
|
 |
I've just uploaded a new version of the component that should solve the problem with the hierarchical controls.
I'm not sure what caused the double lines.
I'd have to play with your code a bit to figure it out.
You no longer have to explicitly call graphicalOverlay.Add() when you add controls to the form.
The component detects them automatically now.
Somehow I missed replying to your post. I hope I sent you an email and didn't just leave you hanging.
If you'd still like me to take a look at it, you can send me the code via private email.
|
|
|
|
 |
|
 |
I forget how I fixed it, but I ended up figuring out something. I'm not even at that job anymore so I can't update it to the new version, though
|
|
|
|
 |
|
 |
I was able to draw line over axAcroPDF control. but after selecting the pdf file, i couldn`t redraw the line. I tried calling Invalidate(), but failed. Can u suggest how draw over the pdf file displayed in axAcroPDF control
-- Manjusha
|
|
|
|
 |