|
use RegExp
"When the only tool you have is a hammer, a sore thumb you will have."
|
|
|
|
|
 This seems to work - i'm sure it can be optimised though:
string s = "0 @IQLNP-M7@ INDI" + Environment.NewLine;
s += "1 NAME Benoni /THOMPSON/" + Environment.NewLine;
s += "2 GIVN Benoni" + Environment.NewLine;
s += "2 SURN THOMPSON" + Environment.NewLine;
s += "1 AFN QLNP-M7" + Environment.NewLine;
s += "1 SEX M" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 BIRT" + Environment.NewLine;
s += "2 DATE 14 Apr 1782" + Environment.NewLine;
s += "2 PLAC Alstead, N.h." + Environment.NewLine;
s += "1 DEAT" + Environment.NewLine;
s += "2 DATE 24 Oct 1857" + Environment.NewLine;
s += "2 PLAC Shalersville, N.h." + Environment.NewLine;
s += "1 FAMS @F6073064@" + Environment.NewLine;
s += "1 FAMC @F6073065@" + Environment.NewLine;
s += "0 @IQLNP-KV@ INDI" + Environment.NewLine;
s += "1 NAME Job /THOMPSON/" + Environment.NewLine;
s += "2 GIVN Job" + Environment.NewLine;
s += "2 SURN THOMPSON" + Environment.NewLine;
s += "1 AFN QLNP-KV" + Environment.NewLine;
s += "1 SEX M" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 FAMS @F6073065@" + Environment.NewLine;
s += "0 @IQLNP-L2@ INDI" + Environment.NewLine;
s += "1 NAME Lovice /CRANE/" + Environment.NewLine;
s += "2 GIVN Lovice" + Environment.NewLine;
s += "2 SURN CRANE" + Environment.NewLine;
s += "1 AFN QLNP-L2" + Environment.NewLine;
s += "1 SEX F" + Environment.NewLine;
s += "1 SOUR @S01@" + Environment.NewLine;
s += "1 FAMS @F6073065@" + Environment.NewLine;
int index = 0;
System.Collections.ArrayList indexList = new System.Collections.ArrayList();
indexList.Add(0);
while (index != -1)
{
index = s.IndexOf(Environment.NewLine + "0 ", index + 1, s.Length - (index + 1));
if(index != -1)
{
indexList.Add(index);
}
}
string[] splitStrings = new string[indexList.Count];
for(int i = 0 ; i < indexList.Count ; i++)
{
if(i == indexList.Count - 1)
{
splitStrings[i] = s.Substring(Convert.ToInt32(indexList[i]), s.Length - Convert.ToInt32(indexList[i]));
}
else
{
splitStrings[i] = s.Substring(Convert.ToInt32(indexList[i]), Convert.ToInt32(indexList[i+1])-Convert.ToInt32(indexList[i]));
}
if(splitStrings[i].StartsWith(Environment.NewLine))
{
splitStrings[i] = splitStrings[i].Substring(Environment.NewLine.Length, splitStrings[i].Length - Environment.NewLine.Length);
}
}
foreach(string newString in splitStrings)
{
MessageBox.Show(newString);
}
|
|
|
|
|
I created a Bitmap object like so
private void FOrm1_Paint( object sender, PaintEventArgs e )
{
Bitmap bmp = new Bitmap(100, 100, e.Grpahics);
}
what I want to do is draw rectangles and things like that inside. But inorder to do that I need to get a graphics object of its surface.
Anyone know how or pointers or links?
Maybe I have to convert it to a HBitmap, I font know!
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
what I want to do is draw rectangles and things like that inside. But inorder to do that I need to get a graphics object of its surface.
You already have a Graphics object embedded within the PaintEventArgs, you are using it when you are creating the Bitmap object above when you access it like e.Graphics . You can continue using this object such as
e.Graphics.DrawLine(0, 0, this.Width, this.Height);
or
Graphics grfx = e.Graphics;
grfx.DrawLine(0, 0, this.Width, this.Height);
Either way works. HTH
-Nick Parker
|
|
|
|
|
yeah but its not contained within the bitmap. I want the bitmap to be a container so to speak. It will eventually be moved outside this after testing and then just draw the bitmap
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
yeah but its not contained within the bitmap. I want the bitmap to be a container so to speak. It will eventually be moved outside this after testing and then just draw the bitmap
Not exactly sure what you mean by this Ista, check out my article Web Graphics On The Fly in ASP.NET[^] if you are still having questions about drawing to a Bitmap object. This articles covers the concept under ASP.NET but the idea is still the same whether or not it is for the web or a Windows application.
-Nick Parker
|
|
|
|
|
Like take MFC. to draw within a bitmap object you get a CDC object then call FillRect and such commands. Graphics object is just a context anyhow so how would I get a context to the bitmap?
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
Ista wrote:
Graphics object is just a context anyhow so how would I get a context to the bitmap?
Not exactly sure what you mean, are you having a problem with the following (which is within the article)? This ties the Graphics object to your Bitmap object.
Bitmap bmp = new Bitmap(this.Width, this.Height, PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bmp);
-Nick Parker
|
|
|
|
|
Your my hero Nick
thanks,
nick
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
I got this sample from:
http://samples.gotdotnet.com/quickstart/util/srcview.aspx?path=/quickstart/howto/samples/cryptography/fileencrypt/encrypt.src&file=CS\fileencrypt.cs&font=3
Just wondering why there isn't a "key" in the code: You need a key for DES encryption don't you?
Here's the code snippet:
FileStream fs = new FileStream("EncryptedFile.txt",FileMode.Create,FileAccess.Write);
DESCryptoServiceProvider des = new DESCryptoServiceProvider();
ICryptoTransform desencrypt = des.CreateEncryptor();
CryptoStream cryptostream = new CryptoStream(fs,desencrypt,CryptoStreamMode.Write);
cryptostream.Write(bytearrayinput,0,bytearrayinput.Length);
cryptostream.Close();
Thanks.
norm
|
|
|
|
|
Norm
If the Key property is not set in DESCryptoServiceProvider, it's auto-initialized to a random value. Since the example merely encryts and decrypts in the same session this doesn't really matter, but of course in a Real World Example (tm), the key would either be accepted from the user (as a password and then preseumably hashed by MD5 or something) or would be saved somewhere (eek!).
Cheers, Julian
Program Manager, C#
This posting is provided "AS IS" with no warranties, and confers no rights.
|
|
|
|
|
Hey guys,
My friend and I just finished up an article describe a product of ours called TwainSharp. I was wondering if you guys wouldn't mind taking a look at the article to see if it would be a good fit to post on code project or not.
http://xsdev.net/tutorials/twainsharp/
Thanks,
Steven
|
|
|
|
|
or you explaining or selling. Twain coms are easy to use anyhow.
I'm not an expert yet, but I play one at work. Yeah and here too.
|
|
|
|
|
i am trying to write dg tablestyle grid column widths to the registry:
opening and creating keys is just fine, i can open regedit and see the keys.
it is when i try to assign a key value to the width of a column that i get the errors.
here is how i save the key:
<br />
Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width);<br />
and here is how i am trying to retrieve the key:
<br />
int ID = Param.GetValue("IHDetailIDWidth");<br />
when i don't run the second line of code, i get no errors, and it is writting to the registry just fine.
when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object.
it highlights the section of code where i set the value though.
any ideas on what i'm doing wrong?
|
|
|
|
|
mikemilano wrote:
when i try to run the code to retrieve the values is when i get this error: Object reference not set to an instance of an object.
Are you creating your Param object before you call the GetValues() method?
For example:
MyAppSettings Param = new MyAppSettings();
...
Param.GetValue("IHDetailIDWidth");
Also, check in your GetValue methods code to make sure all objects referenced have been created.
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
i am creating a Param object before i call GetValues()
here's a little more of the code with the 2 methods i'm using.
I can comment out either one of the 'problem' lines, and the methods work fine, but it is when both are not commented that i get the object error.
private void CreateStyles(DataGrid dg)
{
DataGridTableStyle style = new DataGridTableStyle();
style.MappingName = "IssueHistory";
DataGridTextBoxColumn DetailID = new DataGridTextBoxColumn();
DetailID.MappingName = "DetailID";
DetailID.WidthChanged += new EventHandler(this.SaveIssueGrid);
RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software");
RegistryKey SC = softwareKey.OpenSubKey("SC");
if( SC != null)
{
RegistryKey Param = SC.OpenSubKey("Param");
if(Param != null)
{
DetailID.Width = (int)Param.GetValue("IHDetailIDWidth",50);
}
}
}
void SaveIssueGrid(object sender, EventArgs e)
{
RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey("Software",true);
RegistryKey SC = softwareKey.CreateSubKey("SC");
RegistryKey Param = SC.CreateSubKey("Param");
Param.SetValue("IHDetailIDWidth",this.dgIssueHistory.TableStyles["IssueHistory"].GridColumnStyles["DetailID"].Width);
}
sorry for the big code post, but i've been working on this for hours with the same results.
|
|
|
|
|
Sorry for the late reply.
Since you know the keys/subkeys that you want to open, try and open/create them all at once. This gets rid of the multiple CreateSubKey/OpenSubKey statements which may be part of the problem.
I was able to get a small example working, that I hope will help you. Create a new C# Windows Application and place 2 buttons (btnRead and btnWrite), one label (label1) on the form. Add the Click events for the two buttons using the Designer Property Grid. Replace the generated Click events with the following code:
<code>
private void btnRead_Click(object sender, System.EventArgs e)
{
RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param");
if ( softwareKey != null )
{
int x = (int)softwareKey.GetValue("IHDetailIDWidth", 50);
label1.Text = x.ToString();
}
}
private void btnWrite_Click(object sender, System.EventArgs e)
{
RegistryKey softwareKey = Registry.LocalMachine.OpenSubKey(@"Software\SC\Param", true);
softwareKey.SetValue("IHDetailIDWidth",this.Width);
}
</code>
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
thanks for the help .. this has made me realize my problem is in the event handler and not specific to the registry.
that is a great shortcut for just opening one key. i wasn't aware you could do it that way.
i do appreciate the help, .. i'll start a new thread on the new subject.
|
|
|
|
|
Hello!
I tried, but I don't know why I failed, I think it should be quite simple ...
Could anybody pleas help me ...
I try to make a screenshot of a window and put it in a picturebox in my program. Anybody here who can help me? (the handle of this window is known)
thx
|
|
|
|
|
I have a document in excel with several sheets, But I would like to build a listbox with the list of these sheets (more interactive).
Thank in advance.
bye
-=zoltx=-
|
|
|
|
|
|
I look for the equivalence for c# in ADO.NET. I can t find that. Could you help me ?
-=zoltx=-
|
|
|
|
|
I would like to write the width of a cell in a datagrid to the registry when a user changes the size.
I'm using a TableStyle to customize this DataGrid. ( just from the code, not the gui )
I have a method named: SaveSettings() which writes the current width of the datagrid cells to the registry.
The problem is that I can not figure out how to trigger this method.
Here is how I setup my dg column .. can someone help me with a way to trigger a method on change of the width of this column?
<br />
DataGridTextBoxColumn DetailID = new DataGridTextBoxColumn();<br />
DetailID.HeaderText = "Detail ID";<br />
DetailID.MappingName = "DetailID";<br />
DetailID.Width = 50;<br />
DetailID.WidthChanged
Thanks in advance.
|
|
|
|
|
DetailID.WidthChanged += new EventHandler(MyIDColumnWidthChanged);<br />
Then write the method body for MyIDColumnWidthChanged .
See Consuming Events[^] for further help on hooking up the event.
Roger Stewart
"I Owe, I Owe, it's off to work I go..."
|
|
|
|
|
Thank You very much. It works great! Would not have been able to do it without the consuming events link also =)
|
|
|
|