|
Yeah, don't use Graphics g = Graphics.FromImage(new Bitmap())
Have two images, and two graphics objects, draw onto the images, dispose of the graphics objects like you should, and when you want to merge the two draw one image ontop of the other or whatever:
Bitmap ImageOne = new Bitmap(1536, 1536);
Bitmap ImageTwo = new Bitmap(1536, 1536);
private void Form1_Load(object sender, EventArgs e)
{
Graphics g = Graphics.FromImage(ImageOne);
g.DrawRectangle(Pens.Red, 0, 0, 100, 100);
g.Dispose();
g = Graphics.FromImage(ImageTwo);
g.DrawRectangle(Pens.Blue, 50, 50, 100, 100);
g.Dispose();
}
...
Bitmap b = new Bitmap(Properties.Resources.myimage);
Graphics g = Graphics.FromImage(b);
g.DrawImage(ImageOne);
g.DrawImage(ImageTwo);
g.Dispose();
pictureBox1.Image = b;
Of course you'll need to set a transparent colour for your images, otherwise one will just cover up the other.
My current favourite word is: I'm starting to run out of fav. words!
-SK Genius
Game Programming articles start - here[ ^]-
|
|
|
|
|
yeaht thats what i thought but didnt know that i can make transparent too
thanks
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
You can also use the ImageAttributes class, which an overload of DrawBitmap will take, to specify transparency, overall, or a range of colors to use for the mask.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
I have setup a DataView to read hundreds of DataTables multi or single dimensions. I now wish to be able to change data in selected columns using text boxes a search phrase and column, and also an update phrase and column (see below). The question, how do I tie the columns to the DataTable showing in the DataView.
strDataTableName and dimensions come from comboBoxes.
switch (strDataTableName)
{
case "strA":
{
DataView dvTP = new DataView(dsCS.dsI[dim].A);
dataGridViewVariables.DataSource = dvA;
this.Refresh();
break;
}
}
private void buttonUpdate_Click()
{
String strSearchPhrase = textBoxSearchPhrase.Text;
String strSearchColumn = textBoxSearchColumn.Text;
String strUpdatePhrase = textBoxUpdatePhrase.Text;
String strUpdateColumn = textBoxUpdateColumn.Text;
}
I would appreciate any help.
Michael
|
|
|
|
|
I wrote an XML file using the following code:
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
settings.IndentChars = "\t";
settings.NewLineOnAttributes = true;
settings.Encoding = Encoding.Unicode;
XmlWriter writer = XmlWriter.Create(String.Concat(Application.StartupPath, "\\Contest Organizer.xml"), settings);
writer.WriteStartElement("Settings");
writer.WriteElementString("Topmost", checkBox_topmost.Checked.ToString());
writer.WriteElementString("StandardTab", checkBox_standardtab.Checked.ToString());
writer.WriteElementString("FormBorder", checkBox_formBorder.Checked.ToString());
writer.WriteElementString("RowHeight", nUD_rowHeight.Value.ToString());
writer.WriteElementString("Formula", textBox_formula.Text);
writer.WriteElementString("Precision", nUD_precision.Value.ToString());
writer.WriteEndElement();
Then I referenced msdn (http://msdn.microsoft.com/en-ca/library/ms162529(VS.80).aspx[^]) and tried to read it using the following code:
using(XmlReader reader = XmlReader.Create(String.Concat(Application.StartupPath, "\\Contest Organizer.xml")))
{
reader.ReadToFollowing("Precision");
checkBox_topmost.Checked = reader.ReadElementContentAsBoolean("Topmost", "");
}
However, this generated an error. What is the proper way of reading?
Thanks in advance.
|
|
|
|
|
Hi,
anyone knows how to summon a drop-list while writing in a textbox(i big multiline textbox)?
Something like what you see in visual studio
Thanks
|
|
|
|
|
Will ComboBox work for you?
|
|
|
|
|
Do you mean AutoComplete? If so set the textbox's autocompletesource, autocompletemode, and if needed autocompletecustomsource. If you use the autocompletecustomsource you can create an instance of AutoCompleteStringCollection and add your strings to that.
Dave
|
|
|
|
|
Hi,
I've got a quick question about exception handling.
Ive got a program which is continuously accessing a network. 1/10 times the program would crash giving an exception saying the current port was in use.
This exception only occured when the user changed the listening port, so it was going to happen very seldomly in release.
I found an easy fix for the problem was to put some try blocks around the problem code, and catch an IO exception.
When the IO exception was fired, the method would cease operating (return). The program automatically fixed itself within 200ms (because of an internal timer which rescanned the network.
Do people do this often in industry? i.e
<br />
<br />
private void Foo()<br />
{<br />
try<br />
{<br />
owdEnum = OneWireAccessProvider.getAllDeviceContainers();<br />
}<br />
catch (OneWireIOException) { return; }<br />
<br />
<br />
}<br />
<br />
Cheers,
|
|
|
|
|
If there's no way to stop the program from trying this, if you can't tell ahead of time that this error will occur, then this is probably the best you can do.
Christian Graus
Please read this if you don't understand the answer I've given you
"also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )
|
|
|
|
|
In General Christian is right, however, there is nearly always a method for checking for an error without an exception, otherwise the exception would have never been thrown. In most enterprise environments I find it is more important to trace an exception all the way down to the root cause and use if statements to avoid an exception when possible.
Obviously, I do not take this to an extreme case but yes, I have used the Win32 API to check file handles for locks rather than using the built in File methods which throw exceptions.
Need a C# Consultant? I'm available.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
|
|
|
|
|
I've been slowly fiddling with C# these last couple days, and something bothersome came up. I want to draw a line from a point (150,300) on a form that's (300,300). When I move my mouse, using trig, I want to draw from the point mentioned before to a spot towards the mouse. However, when I start to move further to the side, my accuracy become a bit off. If I did a bad job of explaining (and I probably did!), the link below is a screen shot of what I mean .
Screenshot Here[^]
Now, before it's suggested, I do not want to simply draw the line from the point to whatever mouse position (using e.X and e.Y) because afterwards, I want to use this technique for something else. Here's the snippet of my code:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X<=300 && e.X>=0 && e.Y>=0 && e.Y<=300)
{
DistancePoints = (float)Math.Sqrt(Math.Pow(e.X - 150, 2) + Math.Pow(288 - e.Y, 2));
angle = (float)Math.Acos((e.X - 150) / DistancePoints) * (float)(180 / Math.PI);
double radians = angle * (Math.PI / 180);
movey = (float)Math.Sin(radians%360) * 200;
movex = (float)Math.Cos(radians%360) * 200;
}
}
private void Form1_Paint(object sender, PaintEventArgs e)
{
Graphics g = e.Graphics;
SolidBrush LineC = new SolidBrush(Color.Red);
if (method1)
{
Pen Thing = new Pen(Color.Red, 3);
g.DrawLine(Thing, 150, 300, 150+movex, 300-movey);
}
}
I realize that the error most likely occurs because I'm drawing in fractions of a pixel when doing my calculations, and as such, perhaps C# cannot draw it. Or perhaps I'm wrong. If anyone knows what I may do to alter my code, or what I need to add in order for the accuracy to be spot on, it would be much appreciated! I'm in quite a pickle to be honest! Thanks in advance
|
|
|
|
|
Well man, I'm not sure to be honest, but I'll take a stab since no one else has answered you. My initial guess is, like you suspected, dealing with fractions of a pixel when the Form deals only with whole number pixels.
Have you played around with Math.Round ? Perhaps rounding to the nearest value, rather than truncating, will produce better results?
|
|
|
|
|
Hi
I have a small problem here which I am trying to solve .
I have many Windows Forms in my application which I want to call and show each one based on its name , the name is stored in a database table as a string variable , this table is changeable by the user .
I repeat the only thing I know about the Form is its name as a string variable .
assume no parameters are to be passed to the Form >
any Ideas
Thanks
We will Either find a way , or make one .
|
|
|
|
|
Is the form you're looking for already opened? If so, you could call Application.OpenForms and find the opened form based on the name.
If your form isn't opened and you need to instantiate and display one based on the name, you can use Reflection. In particular, something like GetType.Assembly.GetType("TheNameGoesHere")
Life, family, faith: Give me a visit.
From my latest post: "And you think, 'To keep my anti-Judaic theology alive I must reinterpret this verse too as being a blessing for Christians and not for Jews. I know it strains all manner of principles of interpretation. I don’t read the newspaper this sloppily, but, man, I have a theology to defend.'"
Judah Himango
|
|
|
|
|
can you be more clear about the second case , Create an instance of a form by the form name as string only ?
thanks
|
|
|
|
|
I pointed you in the right direction already: Type theFormWeAreLookingFor = this.GetType().Assembly.GetType("TheNameGoesHere")
From there, you've got a Type. Look for the GetConstructor method, and call invoke on that. Voila! You have yourself a form. Read up on Reflection if you need more -- Gareth linked to the MSDN article in his reply to you.
|
|
|
|
|
unitecsoft,
Reflection[^]
Regards,
Gareth.
(FKA gareth111)
|
|
|
|
|
I created an add-in for Visual Studio that I want to use. Everything works like I want it too. However, I want to be able to get rid of the item on the toolbar when it is deactivated. Right now for some reason it is always on my menu. Even if I go into Add-In Manager and uncheck everything.
Can someone tell me how I could get rid of this option? I would like to have it remove itself once Visual Studio closes.
Thanks
Steve Welborn
Phat Solutions
|
|
|
|
|
I'm not sure. Perhaps this would be a question better suited for the Visual Studio[^] forum or the MSDN Visual Studio Extensibility[^] forum.
Life, family, faith: Give me a visit.
From my latest post: "And you think, 'To keep my anti-Judaic theology alive I must reinterpret this verse too as being a blessing for Christians and not for Jews. I know it strains all manner of principles of interpretation. I don’t read the newspaper this sloppily, but, man, I have a theology to defend.'"
Judah Himango
|
|
|
|
|
You are probably right. I wonder if I can get by posting there and not get called out on double posts?
Thanks for the reply anyway.
Steve Welborn
Phat Solutions
|
|
|
|
|
Actually it doesn't matter. I talked myself out of even needing such a feature.
Steve Welborn
Phat Solutions
|
|
|
|
|
is it a better to dispose an object first before Removeing it from the parent control or vice versa. My next question is that if i dispose the object then how could the complier finds this object to be removed like as follows.
mycontrol.Dispose();
parent.Control.Remove(myControl);
|
|
|
|
|
Remove the control before disposing it. You'd probably end up with a runtime exception otherwise.
Disposing something does not set it to null. Disposing something merely releases any unmanaged resources, such as Win32 handles.
Life, family, faith: Give me a visit.
From my latest post: "And you think, 'To keep my anti-Judaic theology alive I must reinterpret this verse too as being a blessing for Christians and not for Jews. I know it strains all manner of principles of interpretation. I don’t read the newspaper this sloppily, but, man, I have a theology to defend.'"
Judah Himango
|
|
|
|
|
Dispose should only be called when you want to free the resource and have it await garbage collection. So never call Dispose on an object then try to access the reference to it...
-Spacix
All your skynet questions[ ^] belong to solved
I dislike the black-and-white voting system on questions/answers.
|
|
|
|
|