|
If you're using a managed language (vs. a vanilla script) to automate the process, I recommend using the CSharpCodeProvider class. For example, to compile HelloWorld.cs to an .exe , do the following:
CSharpCodeProvider cp = new CSharpCodeProvider();
ICodeCompiler icc = cp.CreateCompiler();
CompilerParameters parms = new CompilerParameters();
parms.GenerateExecutable = true;
parms.OutputAssembly = Output;
CompilerResults results = icc.CompileAssemblyFromFile (parms, "HelloWorld.cs");
/ravi
|
|
|
|
|
Wow! I didn't know you could do that! Five points.
|
|
|
|
|
I'm new to XML, but wat I'm trying to do is this.
I have a XML file with config settings and language items
e.g.
<XML>
<Config>
<Port>com1</Port>
<Baud>9600</Baud>
</Config>
<Language>
<Item No="1000" Text="Hello world" />
<Item No="2000" Text="Good Bye" />
</Language>
</XML>
I read the Config elements by using GetElementByTagName, so this is no problem.
I'm looking for a simmular way of selecting the language items so I can do somthing like
psedu code
Lang = XMLSetup.GetElementsByTagName("Language")[0];
XmlElement LangText= (XmlElement)Setup;
textbox.text=LangText.GetElementByAttribute("No","1000").GetAttribute("Text")
The last line selects the "value on an attribute, depending on an other attribute"
Could this be done?
If I change the structure of of my XML file to somthing like...
...
<Language>
<Item No="1000">
<Text>Hello world</Text>
</Item>
could it be done then??
Any ideas on how to format the XML and do the selection?
I'm used to work with databases, and XML could be used as a databse, or???
If you use an SQL table, you can simply do "select Text from Language where No="1000"...
Thanksfull for any advice
|
|
|
|
|
The trick to doing this is fairly easy://Item[@No='1000'] Basically, this searches for all elements from the root that match Item where there is an attribute No with the value 1000. The @ symbol is used to indicate that it's an attribute.
|
|
|
|
|
I don't follow you here...
Can you give me an example of how to write that in C#?
Thanks!
|
|
|
|
|
System.Xml.XmlDocument xmlDocument = new System.Xml.XmlDocument();
xmlDocument.Load(@"c:\text.xml");
System.Xml.XmlNodeList xmlNodeList = xmlDocument.SelectNodes("//Item[@No='1000']");
foreach (System.Xml.XmlNode xmlNode in xmlNodeList)
{
Console.WriteLine(xmlNode.Value);
}
happy coding
regards,
mark
|
|
|
|
|
I get the following error message sometime when i Navigate to a html file through the webbrowser control C#. Has anyone every comes across while loading an html file. thanks
Action canceled
Internet Explorer was unable to link to the Web page you requested. The page might be temporarily unavailable.
Please try the following:
Click the Refresh button, or try again later.
If you have visited this page previously and you want to view what has been stored on your computer, click File, and then click Work Offline.
For information about offline browsing with Internet Explorer, click the Help menu, and then click Contents and Index.
Internet Explorer
|
|
|
|
|
Type your address in a web browser and see if that address exists or not.
When you're alone in the Dark, Fear will protect you...
|
|
|
|
|
yes i does work first it asked me for my login and password after that i tooke me to the defualt IIS page. I get that error message randomally. sometimes i do get it and someteimes i don't while running my c# app that has webbrowser control in it .
|
|
|
|
|
I have a single instance CAB application.
What I would like to have happen is when a second instance tries to run, it instead passes the argruments to currently running instance, and that instance processes those arguments.
Something like,
_mainForm.Activate(args);
I have this in my ShellMainApplication Main method
bool ok;
Mutex m = new Mutex(true, "InfinityMMSC", out ok);
// app is already running, something needs to be done here
// the running app should process the arguments
if (!ok)
{
// THIS IS WHERE I WOULD LIKE THE ARGUMENTS TO BE PASSED TO THE RUNNING APP
MessageBox.Show("Another instance is already running.");
return;
}
Is there a way to do this?
|
|
|
|
|
I am currently designing my first serious windows application, and I'm wondering whether it's worth using the DirectX libraries.
The application is going to be 2D (although I may implement some 3D elements at a later date), but I don't want it to look like a standard windows application. I'd like to use bitmap images to define the look of the program elements. I don't want the normal title bar on every window and sub-window, I don't want it to be color schemed like typical Windows forms, and there's a good chance that not every element is going to be a uniform shape. The program will need to handle lots of bitmap images simultaneously, with alpha channel support for formats like PNG. I'll also be making use of sound files like mp3s or ogg vorbis.
Just to clarify. This is not technically a game that I'm making. It's a table-top simulator, for playing games like Dungeons&Dragons. So animations and such are not really a priority.
With that in mind, I am wondering...
A) Can the standard Windows libraries handle what I'd like to do?
B) What if any benefits would I gain by using Managed DirectX in this primarily 2D application?
|
|
|
|
|
As a personal opinion I would go for WPF[^] instead of using Forms or DirectX directly.
WPF allows you to use the potential of DirectX but at a higher level.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I second that. Sounds like a great fit for WPF.
Generico300 wrote: A) Can the standard Windows libraries handle what I'd like to do?
The 2D stuff, yes - and any 3D stuff you want to write yourself.
Generico300 wrote: B) What if any benefits would I gain by using Managed DirectX in this primarily 2D application?
Is managed DirectX even supported anymore?
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Managed DirectX has been effectively superceded by XNA. Unfortunately XNA is geared to pushing cross platform development to console, so it misses a whole bunch of features. New development for DirectX should either use the unmanaged API directly thru C++/CLI, or SlimDX (an open source wrapper) if XNA won't cut it.
|
|
|
|
|
Mark Churchill wrote: Managed DirectX has been effectively superceded by XNA.
That's been my understanding for quite a while,
since it was dropped from the SDK.
It still gets asked about often
Thanks!
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
I have a databound gridview on a form in which two columns are formatted numerically to two decimal places. If either of these columns has the value edited and left null, the default error dialog appears. I am having difficulty finding an event that fires before the formatting is attempted, that will allow me to display a custom error message or set a default value in the appropriate cell. I have tried setting the default null value of the column to 0 but that hasn't helped.
Thank you in advance!
|
|
|
|
|
You may be able to trap and prevent the DataGridView error from displaying via the grid's DataError event. You can definitely Cancel grid errors via that event. You may also want to take a look at the CellFormatting event of the DataGridView to see if you can use that to override numeric nulls.
Just a couple of thoughts. Good luck...
|
|
|
|
|
The situation is that I have utility libraries that are used by both ASP.NET and WinForm/console applications. Occasionally these libraries need to reach into the environment to get information. Since the environments are so different I was looking for suggestions on how to hide those differences in the libraries. Suggestions?
Haven't just been bitten by concurrency issues surrounding static variables in ASP.NET applications the specific problem at hand is storing session variables. In ASP.NET you need to store them in HttpContext.Current.Session and in winform/console apps you would simply use a static variable. How do I provide a storage mechanism that is transparent to which environment it is running in?
I suspect I could write a class that determines the environment (how do I do that?) and either stores the data in Session or a private hashtable for winforms. I'm not that familiar with the class loader. Would I avoid dragging in the Web assemblies if I use fully qualified names surrounded by environment if statements (rather than using statements)?
eg:
if (isAsp){
HttpContext.Current.Session["xxx"] = value;
} else {
winSession["xxx"] = value;
}
Help, suggestions appreciated.
|
|
|
|
|
I dropped using session altogether in favor of writing stateless apps. It works fairly well when done with restraint and loading only appropriate data when necessary. I was actually surprised at how much performance I could actually squeeze out of a system with no cache whatsoever.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
If you check for the existence of session and if it doesn't exist use static such as checking System.Web.HttpContext.Current
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
How can I check for the existence of System.Web.HttpContext.Current without draggin the System.Web assemblies into my windows apps?
|
|
|
|
|
I wouldn't call it dragging since the assembly is already installed in the GAC. I don't know how to use reflection to check to see if an Assembly is loaded but that would be the other method.
Need software developed? Offering C# development all over the United States, ERL GLOBAL, Inc is the only call you will have to make.
Happiness in intelligent people is the rarest thing I know. -- Ernest Hemingway
Most of this sig is for Google, not ego.
|
|
|
|
|
Would something like the following be useful:
System.Reflection.Assembly.GetEntryAssembly().GetLoadedModules()
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hay,
Im new to these forums a friend recommended them!
I have created a Game Of Life in C#,
and the only thing to make it complete is a open and save secton,
the full game code is below:
[code]using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Text;
using System.Windows.Forms;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
private int SQsize = 25;
private int[,] paintSQ = new int[50, 50];
private int shape = 1;
private int gridLines = 1;
private int maxRow = 20;
private int maxCol = 20;
private int gridSize = 500;
private int speed = 100;
public Form1()
{
InitializeComponent();
}
private void pictureBox1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{
//Paint grid
if (gridLines == 1)
{
Graphics grid = e.Graphics;
Pen myPen = new Pen(Color.Black, 1); //create a pen object
for (int a = 0; a <= this.gridSize; a += this.SQsize)
{
grid.DrawLine(myPen, 0, a, gridSize, a); //use the DrawLine Horizontal
grid.DrawLine(myPen, a, 0, a, gridSize); //use the DrawLine Vertical
}
myPen.Dispose();
}
Graphics paint = e.Graphics;
SolidBrush myBrush = new SolidBrush(colorDialog1.Color);
if (gridSize == 500 && SQsize == 10)
{
this.maxCol = 50;
this.maxRow = 50;
toolStripStatusLabel1.Text = "Grid Size: Large 50x50";
}
if (gridSize == 500 && SQsize == 25)
{
this.maxCol = 20;
this.maxRow = 20;
toolStripStatusLabel1.Text = "Grid Size: Large 20x20";
}
if (gridSize == 500 && SQsize == 50)
{
this.maxCol = 10;
this.maxRow = 10;
toolStripStatusLabel1.Text = "Grid Size: Large 10x10";
}
if (gridSize == 250 && SQsize == 10)
{
this.maxCol = 25;
this.maxRow = 25;
toolStripStatusLabel1.Text = "Grid Size: Medium 25x25";
}
if (gridSize == 250 && SQsize == 25)
{
this.maxCol = 10;
this.maxRow = 10;
toolStripStatusLabel1.Text = "Grid Size: Medium 10x10";
}
if (gridSize == 250 && SQsize == 50)
{
this.maxCol = 5;
this.maxRow = 5;
toolStripStatusLabel1.Text = "Grid Size: Medium 5x5";
}
if (gridSize == 200 && SQsize == 10)
{
this.maxCol = 20;
this.maxRow = 20;
toolStripStatusLabel1.Text = "Grid Size: Small 20x20";
}
if (gridSize == 200 && SQsize == 25)
{
this.maxCol = 8;
this.maxRow = 8;
toolStripStatusLabel1.Text = "Grid Size: Small 8x8";
}
if (gridSize == 200 && SQsize == 50)
{
this.maxCol = 4;
this.maxRow = 4;
toolStripStatusLabel1.Text = "Grid Size: Small 4x4";
}
int cellRow = 0;
while (cellRow < maxRow)
{
int cellCol = 0;
while (cellCol < maxCol)
{
if (shape == 1)
{
if (paintSQ[cellCol, cellRow] == 1)
{
paint.FillRectangle(myBrush, (cellCol * this.SQsize) + 1, (cellRow * this.SQsize) + 1, this.SQsize - 1, this.SQsize - 1);
}
}
if (shape == 0)
{
if (paintSQ[cellCol, cellRow] == 1)
{
paint.SmoothingMode = SmoothingMode.HighQuality;
paint.FillEllipse(myBrush, new Rectangle((cellCol * this.SQsize), (cellRow * this.SQsize), this.SQsize, this.SQsize));
}
}
cellCol++;
}
cellRow++;
}
myBrush.Dispose();
}
private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
{
if (e.X < pictureBox1.Width && e.Y < pictureBox1.Height && e.X > 0 && e.Y > 0 && e.Button == MouseButtons.Left)
{
int xMouse = 0;
int yMouse = 0;
double xMouse1 = (e.X - 1) / SQsize;
double yMouse1 = (e.Y - 1) / SQsize;
xMouse = (int)System.Math.Ceiling(xMouse1);
yMouse = (int)System.Math.Ceiling(yMouse1);
this.paintSQ[xMouse, yMouse] = 1;
pictureBox1.Refresh();
}
}
private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X < pictureBox1.Width && e.Y < pictureBox1.Height && e.X > 0 && e.Y > 0 && e.Button == MouseButtons.Left)
{
int xMouse = 0;
int yMouse = 0;
double xMouse1 = (e.X - 1) / SQsize;
double yMouse1 = (e.Y - 1) / SQsize;
xMouse = (int)System.Math.Ceiling(xMouse1);
yMouse = (int)System.Math.Ceiling(yMouse1);
this.paintSQ[xMouse, yMouse] = 1;
pictureBox1.Refresh();
}
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
Close();
}
private void colourToolStripMenuItem_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
}
private void smallToolStripMenuItem_Click_1(object sender, EventArgs e)
{
maxRow = 10;
maxCol = 10;
gridSize = 200;
Refresh();
}
private void mediumToolStripMenuItem_Click(object sender, EventArgs e)
{
gridSize = 250;
maxRow = 25;
maxCol = 25;
Refresh();
}
private void largeToolStripMenuItem_Click(object sender, EventArgs e)
{
gridSize = 500;
maxRow = 50;
maxCol = 50;
Refresh();
}
private void exitToolStripMenuItem_Click_1(object sender, EventArgs e)
{
Close();
}
private void helpToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void timer1_Tick(object sender, EventArgs e)
{
int[,] tempPaintSQ = new int[50, 50];
int cellRow = 0;
while (cellRow < maxRow)
{
int cellCol = 0;
while (cellCol < maxCol)
{
int cellAlive = 0;
if (cellCol - 1 >= 0 && cellRow - 1 >= 0 && cellCol - 1 < this.maxCol && cellRow - 1 < this.maxRow)
{
if (paintSQ[cellCol - 1, cellRow - 1] == 1)
{
cellAlive++;
}
}
if (cellCol - 1 >= 0 && cellRow >= 0 && cellCol - 1 < this.maxCol && cellRow < this.maxRow)
{
if (paintSQ[cellCol - 1, cellRow] == 1)
{
cellAlive++;
}
}
if (cellCol - 1 >= 0 && cellRow + 1 >= 0 && cellCol - 1 < this.maxCol && cellRow + 1 < this.maxRow)
{
if (paintSQ[cellCol - 1, cellRow + 1] == 1)
{
cellAlive++;
}
}
if (cellCol >= 0 && cellRow - 1 >= 0 && cellCol < this.maxCol && cellRow - 1 < this.maxRow)
{
if (paintSQ[cellCol, cellRow - 1] == 1)
{
cellAlive++;
}
}
if (cellCol >= 0 && cellRow + 1 >= 0 && cellCol < this.maxCol && cellRow + 1 < this.maxRow)
{
if (paintSQ[cellCol, cellRow + 1] == 1)
{
cellAlive++;
}
}
if (cellCol >= +1 && cellRow - 1 >= 0 && cellCol + 1 < this.maxCol && cellRow - 1 < this.maxRow)
{
if (paintSQ[cellCol + 1, cellRow - 1] == 1)
{
cellAlive++;
}
}
if (cellCol + 1 >= 0 && cellRow >= 0 && cellCol + 1 < this.maxCol && cellRow < this.maxRow)
{
if (paintSQ[cellCol + 1, cellRow] == 1)
{
cellAlive++;
}
}
if (cellCol + 1 >= 0 && cellRow + 1 >= 0 && cellCol + 1 < this.maxCol && cellRow + 1 < this.maxRow)
{
if (paintSQ[cellCol + 1, cellRow + 1] == 1)
{
cellAlive++;
}
}
if (paintSQ[cellCol, cellRow] == 1)
{
if (cellAlive < 2)
{
tempPaintSQ[cellCol, cellRow] = 0;
}
if (cellAlive == 2 || cellAlive == 3)
{
tempPaintSQ[cellCol, cellRow] = 1;
}
if (cellAlive > 3)
{
tempPaintSQ[cellCol, cellRow] = 0;
}
}
else
{
if (cellAlive == 3)
{ tempPaintSQ[cellCol, cellRow] = 1; }
else
{ tempPaintSQ[cellCol, cellRow] = 0; }
}
cellCol++;
}
cellRow++;
}
this.paintSQ = tempPaintSQ;
speedBarMove();
cellcountAliveDead();
pictureBox1.Refresh();
}
private void speedBarMove()
{
if (speedBar.Value == 0)
{
timer1.Interval = 400;
}
if (speedBar.Value == 1)
{
timer1.Interval = 200;
}
if (speedBar.Value == 2)
{
timer1.Interval = 100;
}
if (speedBar.Value == 3)
{
timer1.Interval = 50;
}
if (speedBar.Value == 4)
{
timer1.Interval = 5;
}
}
private void start_Click(object sender, EventArgs e)
{
timer1.Enabled = true;
}
private void stop_Click(object sender, EventArgs e)
{
timer1.Enabled = false;
}
private void Clear_Click(object sender, EventArgs e)
{
int cellRow = 0;
while (cellRow < maxRow)
{
int cellCol = 0;
while (cellCol < maxCol)
{
paintSQ[cellCol, cellRow] = 0;
cellCol++;
}
cellRow++;
}
pictureBox1.Refresh();
}
private void button1_Click(object sender, EventArgs e)
{
colorDialog1.ShowDialog();
}
private void onToolStripMenuItem_Click(object sender, EventArgs e)
{
gridLines = 1;
pictureBox1.Refresh();
}
private void squareToolStripMenuItem_Click(object sender, EventArgs e)
{
shape = 1;
pictureBox1.Refresh();
}
private void circleToolStripMenuItem_Click(object sender, EventArgs e)
{
shape = 0;
pictureBox1.Refresh();
}
private void offToolStripMenuItem_Click(object sender, EventArgs e)
{
gridLines = 0;
pictureBox1.Refresh();
}
private void toolStripMenuItem2_Click(object sender, EventArgs e)
{
SQsize = 10;
pictureBox1.Refresh();
}
private void mediumToolStripMenuItem1_Click(object sender, EventArgs e)
{
SQsize = 25;
pictureBox1.Refresh();
}
private void largeToolStripMenuItem1_Click(object sender, EventArgs e)
{
SQsize = 50;
pictureBox1.Refresh();
}
private void slowToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Interval = 400;
speed = 400;
if (speed == 400)
{
speedBar.Value = 0;
}
}
private void slowToolStripMenuItem1_Click(object sender, EventArgs e)
{
timer1.Interval = 200;
speed = 200;
if (speed == 200)
{
speedBar.Value = 1;
}
}
private void mediumToolStripMenuItem2_Click(object sender, EventArgs e)
{
timer1.Interval = 100;
speed = 100;
if (speed == 100)
{
speedBar.Value = 2;
}
}
private void fastToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Interval = 50;
speed = 50;
if (speed == 50)
{
speedBar.Value = 3;
}
}
private void lightSpeedToolStripMenuItem_Click(object sender, EventArgs e)
{
timer1.Interval = 5;
speed = 5;
if (speed == 5)
{
speedBar.Value = 4;
}
}
private void cellcountAliveDead()
{
int currentAlive = 0;
int currentDead = 0;
int cellRow = 0;
while (cellRow < maxRow)
{
int cellCol = 0;
while (cellCol < maxCol)
{
if (paintSQ[cellCol, cellRow] == 1)
{
currentAlive++;
}
if (paintSQ[cellCol, cellRow] == 0)
{
currentDead++;
}
cellCol++;
}
cellRow++;
}
toolStripStatusLabel2.Text = "Cells Alive: " + currentAlive;
toolStripStatusLabel3.Text = "Dead Cells: " + currentDead;
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
}
}
}
[/code]
I know there is a lot of code there sorry. Im trying to save using the following processes and open in the revers
[code]void saveMyData()
{
Stream outputStream = File.OpenWrite(@"C:\myData.dat");
for (int x = 0; x < myData.Length; x++ )
{
outputStream.WriteByte( myData[x] );
}
outputStream.Close();
}
[/code]
This is the example ive found but i cant figure out how to edit it to work with my code so it will save the current live cells and the current dead cells.
Thanks
b3rt!
|
|
|
|
|
No one is going to go through all the code.
Blog link to be reinstated at a later date.
|
|
|
|
|