|
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.
|
|
|
|
|
Hi There.
I have an app with a Datagridview control showing an overview of jobs. Each job has a status from 0-100%.
What my boss wants me to do is set all jobs at 100% in the datagridview to strike through font. Does anybody have any idea how I can do this? Is it possible?
I have been able to locate the 100% rows and can colour the foreground and background etc, but still cannot set the Strikethrough Property. Anybody know how to do it???
Here is my code to locating the required rows...
private void OverViewColourCoding(DataGridView dg)
{
foreach (DataGridViewRow dgr in dg.Rows)
{
foreach (DataGridViewCell dgc in dgr.Cells)
{
if (Convert.ToString(dgc.Value) == "100%")
{
dgr.DefaultCellStyle.ForeColor = System.Drawing.Color.Gray;
dgr.DefaultCellStyle.BackColor = System.Drawing.Color.LightGray;
}
}
}
}
(I'm sorry if this is a simple question. I'm new to C#)
Thanks
modified on Monday, November 10, 2008 11:36 AM
|
|
|
|
|
Not absolutely sure about this, but DefaultCellStyle has property Font which again has property StrikeOut .
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hi Mika.
Thank you, but I have tried that. For some crazy reason, all the properties under DefaultCellStyle.Font are read only, which really sucks!!!
I think the only way I will be able to do this is by creating a custom class and inheriting the DataGridView class, and allowing the strikethrough this way. BUT, I am new in C# and don't have a clue on how I could do this. (I know how to inherit another class, but not how to modify properties like DefaultCellStyle.Font )
Any help would be great... Thanks...
|
|
|
|
|
Strikeout is read only so you cannot modify it on the fly. Instead create a new font and place it in DataGridViewCellStyle.Font. Something like (I'm not near VisualStudio right now so this may contain several typos):
dgr.DefaultCellStyle.Font = new Font(dgr.DefaultCellStyle.Font, FontStyle.Strikeout);
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
I had a go at this, but couldnt quite get it to work, and I've ran out of time. I'll spend a bit more time on it tomorrow.
It looks like the right lines. I'll give it more attention in the morning and let you know.
Thanks very much for your time on this.
|
|
|
|
|
No problem
If you get stuck tomorrow, send a post on this and let's see if we can help.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hi
Just to let let you know, you got me on the right lines.
The exact code I used was:
dgr.DefaultCellStyle.Font = new Font(new FontFamily("Microsoft Sans Serif"), 8.25F, FontStyle.Strikeout);
Thank you again for your help.
|
|
|
|
|
You're welcome
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Hi there
Let's say I have a txt file with 100.000 words which I'll load into memory. I need to manage this file as a database in order to provide a character prediction application. What method can I use in order to have a fast response, even on embedded devices?
|
|
|
|
|
Speed of search comes through complexity of code. The more indexes you build, the faster it will be, but the more memory it will use.
Christian Graus
Driven to the arms of OSX by Vista.
"Iam doing the browsing center project in vb.net using c# coding" - this is why I don't answer questions much anymore. Oh, and Microsoft doesn't want me to.
|
|
|
|
|
Don't load it into memory. Use a file stream and appropriate indexes and it will be fast as the size of the file increases close to and beyond the amount of available ram for the application, especially on embedded devices.
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.
|
|
|
|
|
One possibility is to use even SQL Server compact edition and with a constantly open connection query potential words from db. This would ease the index building.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Here's a suggestion.
Assuming the file is sorted so the words are in alphabetic order you can treat it as an array of words and use the Seek method to do a binary search.
There are a few caveats e.g. I think you need to use a BufferedStream and it might mean padding words with trailing spaces so you can calculate the offset.
Just a thought - perhaps not completely practical.
|
|
|
|
|
One way to do this would be to split the words up into smaller chunks, and then have *pointers* to keep them together. Consider this small file:
Adrian
Andrea
Andrew
Anthony
Brian
Charles
William
Winston
This could be tokenised like this:
Ad ri an
An dr ea
ew
th on y
Br ia n
Ch ar le s
Wi ll ia m
ns to n
As you can see, the list of choices narrows quite dramatically, the further on you get, and the information becomes quite easy to traverse. In this example, the user types in A and gets a choice of 4 entries. As soon as they press n, it breaks down to 3. Pressing d narrows it down to 2, and they keep going until they get to the end (or choose one out of your selection).
The downside to this approach, is the actual splitting of the words is the time consuming part of the process, but if your solution allows you to preparse them into smaller units up front, the results can be quite dramatic.
|
|
|
|
|
that's a great answer dude!
|
|
|
|
|
Read it and slap it in a tree structure so you can traverse quickly thru the possibilities.
|
|
|
|
|
Try SqlLite[^]- a file system based SQL database engine. Then use normal SQL queries to fetch the required data. It would be much faster.
|
|
|
|
|
A database has a lot of overhead, which you can avoid with your own data structure. I suggest a tree structure where each level takes you one letter farther in the word:
The root will have 26 sons, for the 26 possible first letters. Each of these sons will have up to 26 sons (grandsons of the root) for the (up to) 26 possible second letters, and so on.
1. It saves space because all words sharing a common prefix will use the same path from the root, giving you some compression.
2. It's faster than a database because you don't have to do any time-consuming queries; at each node you have a list of all the possible next characters.
3. When building this tree from your word list, you can increment a counter for each letter added at the current node. This will give you the frequencies for each continuation letter. You can then use these frequencies to predict the most likely continuation.
|
|
|
|
|
here is the first part of an XML file I am trying to parse.
<?xml version="1.0" encoding="utf-16" ?>
- <GPO xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://www.microsoft.com/GroupPolicy/Settings">
- <Identifier>
<Identifier xmlns="http://www.microsoft.com/GroupPolicy/Types">{89AEAFFE-E1F8-4786--6BE2D991625E}</Identifier>
<Domain xmlns="http://www.microsoft.com/GroupPolicy/Types">FQDN of Domain</Domain>
</Identifier>
<Name>Citrix_policy</Name>
<CreatedTime>2008-03-06T23:08:05</CreatedTime>
<ModifiedTime>2008-08-27T20:49:49</ModifiedTime>
<ReadTime>2008-10-24T01:29:41.40625Z</ReadTime>
.....
</GPO>
I am trying to use XPathNavigator but the following code returns the whole xml document
XPathDocument document = new XPathDocument(stream);
XPathNavigator nav = document.CreateNavigator();
XPathNodeIterator node = nav.Select("/GPO/Identifier/Identifier");
string test = node.Current.InnerXml.ToString();
MessageBox.Show(test);
What am I doing wrong?
|
|
|
|
|
Try to use MoveNext method on XPathNavigator after calling Select. Also if you have simple queries, you can use directly SelectNodes for XmlDocument.
The need to optimize rises from a bad design.
My articles[ ^]
|
|
|
|
|
Thanks for pointing me in the right direction, i have figured out how to do a simple query with Xpath, now the next step...
I have a large xml doc that i am parsing it has 2 big sections they have their own nodes in the doc. what will tell me when I have reached the end of the node? so I can kill my loop.
Thanks
|
|
|
|
|