|
Hello,
How can I insert the image of an object Graphics in an other ?
By example, I have two panels : I draw some lines on the first one. How can I copy it to the second panel ? (or only a part of it) ?
Thanks
Troz
|
|
|
|
|
This is a semi-large problem I have with the GDI+ Graphics object. You have no way of accessing the bitmap data that has been drawn on it. The reasoning for this is that the Graphics object may not have a bitmap to pull the data back from (such as when printing).
One work around that might work would be to get the DC (GetHdc), BitBlt the data, then release the DC (ReleaseHdc).
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Thanks a lot
there is the solution, found on http://www.syncfusion.com/FAQ/WinForms/FAQ_c55c.asp
[System.Runtime.InteropServices.DllImportAttribute("gdi32.dll")]
private static extern bool BitBlt(
IntPtr hdcDest, // handle to destination DC
int nXDest, // x-coord of destination upper-left corner
int nYDest, // y-coord of destination upper-left corner
int nWidth, // width of destination rectangle
int nHeight, // height of destination rectangle
IntPtr hdcSrc, // handle to source DC
int nXSrc, // x-coordinate of source upper-left corner
int nYSrc, // y-coordinate of source upper-left corner
System.Int32 dwRop // raster operation code
);
private void button1_Click(object sender, System.EventArgs e)
{
Graphics g1 = panel1.CreateGraphics();
Graphics g2 = panel2.CreateGraphics();
//Drawing on panel1 (g1)
//...
//Copy it to panel2
Size s = panel1.Size;
Image memImage = new Bitmap(s.Width, s.Height, g1);
Graphics memGraphic = Graphics.FromImage(memImage);
IntPtr dc1 = g1.GetHdc();
IntPtr dc2 = memGraphic.GetHdc();
BitBlt(dc2, 0, 0, panel1.ClientRectangle.Width,
panel1.ClientRectangle.Height, dc1, 0, 0, 13369376);
g1.ReleaseHdc(dc1);
memGraphic.ReleaseHdc(dc2);
g2.DrawImage(memImage,0,0);
}
It works with any Graphics object (you can copy a form, a MSChart ...)
Troz
|
|
|
|
|
Oh my lordy!!! How could they not allow static members in interfaces!!! That's soooo irritating. Tick, theres another todo on the C# wish list...
|
|
|
|
|
Use an abstract class instead. An interface provides no implementation.
Logically it doesnt make sense to add a static member to an interface, because at runtime the interface provides u with methods that can be used on an instance of an interface and never the interface directly.
How about just adding it without making it static??? Seeing that it will be used with an instance of the interface.
Maybe even move the static member to the class that implements the interface, although i would have no clue how to access it then. Again the keyword is instance.
Hope this helps
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
What do you do leppie? You have amazing response times - not that I'm complaining. Anyways, I believe (not a language historian or anything) that is makes complete sense. For instance, lets say we have the following interface:
IChalk {
Color color { get; }
void Break();
string SerializeXml();
static IChalk Deserialize( string Xml ); //Cannot actually do the static thang.
}
class GreenChalk : IChalk {
Color IChalk.color { get { return Color.Red; } }
void Break() { throw( new Exception("Damn it!!!") ); }
string IChalk.SerializeXml() {
XmlSerializer sr = new XmlSerializer( this.GetType );
//blah blah
}
static IChalk IChalk.Deserialize( string xml ){
GreenChalk gc = new GreenChalk();
//blah blah
return gc;
}
}
I hate using specific examples for explainations but it'll save on length and confusion.
Now you could just make it deserialize to the instance and remove the need for the static member, but I believe it is more consistant this way; once you instanciate the implementing class you HAVE an IChalk, Deserialize in escence creates another one. So to Deserialize I have to create two versions.
You do point out a good idea that could mirror that though. I could use an abstract class with the Serialization methods in them and do that I guess, but it is definitly a hack in my mind. Unless someone else (or you) can explain why it isn't.
|
|
|
|
|
static functions are generally a bad idea, it presumes how your class will be used.
you are better off using a seperate help classer - see design patterns, GOF - "prefer composition to inheritance" (or something like that).
Personally I think Serialization sucks - have a look a the memento pattern...
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
Cromwell wrote:
What do you do leppie? You have amazing response times - not that I'm complaining.
I'm jobless hovering on a free GPRS connection
Like in the post before mine, I would suggest making a helper class to take care of the static methods This could even be the abstract baseclass for all types of chalk, and the base class would implement IChalk. Else, cant static IChalk Deserialize( string Xml ) become non static, because adding a static member there does not make sense...
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
Else, cant static IChalk Deserialize( string Xml ) become non static, because adding a static member there does not make sense
actually that was my argument. I think it doesn't make sense to not have it static. If it isn't static you have just instanciated two IChalk objects by returning an IChalk object. Also, as I mentioned, if you use the Deserialize as a member that updates/sets the values of the object. You have an invalid IChalk object between the point of instanciation and the Deserialization call. Granted it will be most common that the Deserialization call be made directly following the instanciate or, at least before the object is used, but a solid class wouldn't leave that moment of possibility open. Also, its possible that the deserialization method implemented by some other because they need the IChalk interface wouldn't do a good job of guaranteeing that the class is valid after deserialization. Ie deserialize may very well leave IChalk.color = null when that isn't acceptable because it wasn't specified in the serialized xml. Get my point. I see and realize there are ways of doing things (ie, abstract classes+interfaces, presume good implementation (;/), etc, but I'm a pain in the arse.
|
|
|
|
|
Cromwell wrote:
If it isn't static you have just instanciated two IChalk objects by returning an IChalk object.
You would have to instanciated an IChalk object to use an IChalk object. Remember the type of the IChalk object will not be IChalk, it will be the actuall type of the class
I think we should look back at the definition of an interface and if they really needed in your case. From what I can see, a base class with some abstract methods (those you would use with the original interface) will provided the best solution in your case and it would pretty much function the same.
From MSDN:
An interface:
An interface defines a contract. A class or struct that implements an interface must adhere to its contract. An interface may inherit from multiple base interfaces, and a class or struct may implement multiple interfaces.
Interfaces can contain methods, properties, events, and indexers. The interface itself does not provide implementations for the members that it defines. The interface merely specifies the members that must be supplied by classes or interfaces that implement the interface.
An abstract class:
When a non-abstract class is derived from an abstract class, the non-abstract class must include actual implementations of all inherited abstract members. Such implementations are provided by overriding the abstract members.
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
leppie wrote:
You would have to instanciated an IChalk object to use an IChalk object. Remember the type of the IChalk object will not be IChalk, it will be the actuall type of the class
His point (and a good one) is that he shouldn't have needed to instantiate any object that implements IChalk in order to call Deserialize, by itself Deserialize doesn't need any state at all to operate (since it only creates a new instance of that object and returns a reference as the interface).
I think the class factory pattern would apply well here, have a class/interface that deserializes and creates new instances of objects implementing IChalk.
interface IChalkFactory
{
IChalk Deserialize();
IChalk Create();
void Serialize(IChalk);
} James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
Tanka! Maybe your explaination made more sense than mine did. I have to say the inability to add static members to an interface is quite irritating. Ugh...
So many missing pieces...
|
|
|
|
|
Hi,
I have installed the Enterprise developer version after
uninstalling the beta version of Visual Studio .NET.
The problem is that now I can't execute any application
from the Begin button, neither debugging step by step; it
doesn't matter either the size and number of forms of the
project. In all cases when the form should be shown the
IDE hangs up like if the window shown was disabled. I can
close the application process and the IDE seems to recover
but keeps on hanged up. At the and I must close de IDE
process.
I uninstalled SourceSafe (I installed VS.NET & SourceSafe
at the same time) but nothing changed.
Does anyone knows what is happening and why?, any similar
problem?
Thanks in advance,
Edgar
Edgar Berengena Moreno
Software Engineer
Appeyron Research
|
|
|
|
|
|
Does it just sit there doing nothing or is it really hung (ie responds to nothing)?
For me in about 15 of 100 runs it will stop execution after loading System.Drawing.dll
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
well - im not 100% sure, after a long time the debug bar appears, but still the app does not show, so I just end the process for the app, and the IDE returns to normal.
Email: theeclypse@hotmail.com URL: http://www.onyeyiri.co.uk "All programmers are playwrights and all computers are lousy actors."
|
|
|
|
|
.NET service pack 2.
And I swallow a small raisin.
|
|
|
|
|
Thanks for your reply.
I have already installed it on my computer but keeps on hanging up...
Any other suggestion?
Edgar Berengena Moreno
Software Engineer
Appeyron Research
|
|
|
|
|
|
I had problems with SmartHelp and IDE, dunno if this is related.
Format is allways a solution
MYrc : A .NET IRC client with C# Plugin Capabilities. See
http://sourceforge.net/projects/myrc for more info.
|
|
|
|
|
this is a known problem with vs 7.0, it is not fixed in sp1 pr sp2, there are steps to help the problem but to be honest i can't remember what they are (sorry).
if you post your problems to the microsoft.public.dotnet.languages.csharp newsgroup you will get a lot of help there.
I get it about 4 times out of 10, but I get usually get it to work by clicking the restart toolbar button.
I vaguely remember it also helps if you don't use your system to host a web dev stuff (asp), stopping some of the services on your machine to do with this helps, although it never fixed mine as I don't use the machine for asp stuff.
There is also some stuff on msdn/technet aboput the problem as well.
sorry I couldn't be of much help.
bg
|
|
|
|
|
Our group has encountered the same problem. We have found two things that will "un-hang" the IDE.
1. Disconnect your network connection (I have created a short-cut to enable/disable the connection).
2. Run the NET configuration utility (don't know why this works but it does).
|
|
|
|
|
EdgarBM wrote:
after
uninstalling the beta version of Visual Studio .NET.
Before you installed VS.NET did you make sure to remove all traces of the beta?
Chances are mscoree.dll was still lying around somewhere on your hard drive and that could have screwed some stuff up.
FWIW, when you got the Beta package there were several warnings about not being installed on a primary computer because the recommended way of switching from a beta is to format and reinstall. Fortunately the uninstall actually worked starting with RC0
James
"And we are all men; apart from the females." - Colin Davies
|
|
|
|
|
I've got the solution!
Thanks in advance to everybody who tried to help in anyway.
The solution is to recover a bug on the uninstallation program of the Beta version, it's all explained on:
Q312115 - PRB: Visual Studio Debugger Stops Responding After You Install Post-Beta 2 Build
It's about a service called ".NET Framework Support Service" which is not removed during the uninstall and produces all this problem. You must only to disable it and reinitialize the computer (find it at the Control Panel - Administrative Tools - Services, and disable it through Properties window).
Thanks to everyone.
Edgar
Edgar Berengena Moreno
Software Engineer
Appeyron Research
|
|
|
|
|
In the good old days, when I wanted to associate data structures with a combo-box item I'd use SetItemData.
What is the best method to do this in C# as I can't seem to find a SetItemData method. (Why has MS decided to remove a valuable, tried and tested way).
I must be missing something, I've been through the docs on ComboBox.ObjectCollection but it isn't making sense.
Michael
Time flies like an arrow. Fruit flies like a banana
|
|
|
|