i am making an application which will load and save settings in an xml file. i searched thru all those questions and answers and tried all those methods and i didn’t find solution to my problem. here is the code:
private void DocumentToPrint_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
int x1 = 1;
XmlReader reader = XmlReader.Create("settings.xml");
while (reader.Read())
{
if ((reader.NodeType == XmlNodeType.Element) && (reader.Name == "coordinates"))
{
if (reader.HasAttributes)
{
x1 = int.Parse(reader.GetAttribute("tekst1x"));
}
}
}
reader.Close();
var line1 = textBox1.Text;
Font PrintFont = this.textBox1.Font;
SolidBrush PrintBrush = new SolidBrush(Color.Black);
e.Graphics.DrawString(line1, PrintFont, PrintBrush, x1, 30, new StringFormat());
PrintBrush.Dispose();
}
so its always showing me
this error:
Use of unassigned local variable ‘x1’ even i do have x1 assigned to 1.
on this line
e.Graphics.DrawString(line1, PrintFont, PrintBrush, x1, 30, new StringFormat());
any help will be appreciated. thanks in advance and best wishes.
i edit the question and added the full code
The given code does compile well. It seems like an issue with the IDE. I suppose it’ll be enough to
CleanandRebuildthe solution. However if it does not help, you may try to restart Visual Studio.