|
Brillint, thanks for your quick responce. Saved me hours!
Ian
|
|
|
|
|
Also, you only need one set of brackets:
<br />
if (<br />
cboCeaseType.SelectedValue.ToString() == "2" || <br />
cboCeaseType.SelectedValue.ToString() == "5")<br />
The extra brackets are unnecessary (but won't do any harm).
|
|
|
|
|
*slap on the wrist*
It's about readability, my good man! Seperating those two conditionals with their own set of parens makes it clearer what is being compared.
Jeremy Kimball
Moderation is for monks. -Lazarus Long
And this, too, shall pass away...
|
|
|
|
|
Hi,
I would like to generate rtf code of the picture/image programatically without using richtext box or clip board.
To be more specific I want to create .rtf file of image/pictures ?
Need help in above regard......
Thanx in advance..
Regards,
Jay
|
|
|
|
|
In the RTF specification, pictures can be encoded using hexidecimal or binary encoding. If you use binary (hexidecimal is more common), do not use CR/LF pairs to break lines (as is usual with binary files).
Getting the hexidecimal value of bytes isn't hard. Just loop through the bytes and output base16 char sequences:
Image img = new Bitmap("myimage.bmp");
MemoryStream ms = new MemoryStream();
img.Save(ms);
ms.Seek(0, SeekOrigin.Begin);
StringBuilder sb = new StringBuilder(ms.Length * 2);
byte[] buffer = new byte[4096];
int read = ms.Read(buffer, 0, buffer.Length);
while (read != 0)
{
for (int i=0; i<read; i++) sb.AppendFormat("{0:x2}", buffer[i]);
read = ms.Read(buffer, 0, buffer.Length);
}
string hex = sb.ToString(); It's not exactly the most efficient, but you should get the idea.
There are several sections require to embed a pictures in RTF. Read more about embedding pictures in the RTF specification at http://msdn.microsoft.com/library/en-us/dnrtfspec/html/rtfspec_16.asp?FRAME=true#rtfspec_24[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Hi Steward,
Thanks a lot for the solution.
I have modified the code since there was some compilation error as below
<br />
string strfileName = "PicInHex.rtf";<br />
FileStream MyStream = new FileStream("c:\\" + strfileName, FileMode.Create);<br />
System.IO.StreamWriter MyWriter =<br />
new System.IO.StreamWrite(MyStream,System.Text.Encoding.Default);<br />
<br />
Image img = new Bitmap("myimage.bmp");<br />
MemoryStream ms = new MemoryStream();<br />
img.Save(ms,System.Drawing.Imaging.ImageFormat.Bmp);<br />
ms.Seek(0, SeekOrigin.Begin);<br />
StringBuilder sb = new StringBuilder(Convert.ToInt32(ms.Length * 2));<br />
byte[] buffer = new byte[4096];<br />
int read = ms.Read(buffer, 0, buffer.Length);<br />
while (read != 0){ <br />
for (int i=0; i<<read; i++)<br />
sb.AppendFormat("{0:x2}", buffer[i]); <br />
read = ms.Read(buffer, 0, buffer.Length);<br />
}<br />
string hex = sb.ToString();<br />
MyWriter.Write(hex);<br />
<br />
MyWriter.Close();<br />
MyStream.Close();<br />
I want to get the hex code of the image using the above code then prefix and suffix image rtf syntax in it to get rtf code file
when I try to open the "PicInHex.rtf" (created after executing the above code)using notepad to view the hex code. the NotePad application crashes.
Will you please commnet whether
1. can I open and view the code using notepad (the bmp is of A4 size)
2. Am I correct in approaching the solution?
Let me thank you once again for your co-operation and solution.
Regards,
Jay.
|
|
|
|
|
It was sample code - it wasn't meant to be complete, but to serve as an example.
Notepad is a vanilla (i.e., plain) text editor so it won't view anything for the RTF "code" itself. The image will appear as what it appears in the actual RTF: hex.
So long as your hex-encoding the image and using the right RTF codes, then there really is no other way to approach this without using some third-party library or some RTF control like the RichTextBox .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
public string ImageToRTF(Image img)
{
RichTextBox rtf = new RichTextBox();
Clipboard.SetDataObject(img);
rtf.Paste();
return rtf.Rtf;
}
|
|
|
|
|
Dear Heath Stewart and Gonzalez,
thanks a lot for the solution and guidance, it solves the purpose. I am pasting my complete Demo code.This can be helpful to another developers
private void button1_Click(object sender, System.EventArgs e)
{
string strImageToRTF ="";
string strfileName = "ImageInRTFfile.rtf";
FileStream MyStream = new FileStream("c:\\" + strfileName, FileMode.Create);
System.IO.StreamWriter MyWriter =new System.IO.StreamWriter(MyStream,System.Text.Encoding.Default);
Image img = new Bitmap(@"c:\myimage.bmp");
strImageToRTF = this.ImageToRTF(img);
MyWriter.Write(strImageToRTF);
MyWriter.Close();
MyStream.Close();
}
private string ImageToRTF(Image img)
{
RichTextBox rtf = new RichTextBox();
Clipboard.SetDataObject(img);
rtf.Paste();
return rtf.Rtf;
}
Thanks and Regards,
Jay.
|
|
|
|
|
I have created several new components that I have successfully added to the General tool bar. Method of building and using the new components is pretty much straight out of the C# Unleashed book. I can set the properties I have built into them and I get the expected results. I can compile, it works. Exit VS and run the executable and it still works as intended.
The problem is: Reload the project is VS (2003 edition) and any of the custom properties are reset back to the original defaults.
A property example would be:
<br />
...<br />
private InputMaskType maskType;<br />
public enum InputMaskType {None, Dollars, Percent, Phone}<br />
...<br />
[Description("Sets Predefined Input Mask"), Category("Behavior"),<br />
RefreshProperties(RefreshProperties.All)]<br />
public InputMaskType DisplayMaskFormat<br />
{<br />
get { return maskType; }<br />
set { maskType = value; }<br />
}<br />
...<br />
I haven't come across anything that indicates I have to do something different to store the properties permanently, but if so, please let me know.
|
|
|
|
|
Properties - and practically everything else you do in VS.NET (can't vouch for third-party controls written poorly) - are persisted to the source files, ResX files (localizable resource files), or other similar files. Everything you do in VS.NET can be done with command-line compilers. If you're loosing values when upgrading your projects, then it's usually because ResX files (where localized values may be stored) are referencing older versions of assemblies (most likely FCL assemblies) are the values are disassociated when opening the project in the new version of the IDE.
My suggestion is to not use ResX files unless you have to (to localize resources - not just text - and to manage strings in a single place) and just upgrade your project file, fix any problems, and be done with it.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
The main project this is occurring was upgraded a couple months ago. The losing of properties is a matter of: Open VS2003, setting the properties as I want them, compile and test them to make sure they work, shut down VS2003, reopen the solution a few days later, properties have been reset!
I did look in the source code directory. The ResX file timestamps are current so they are getting updated, indicating that I'm using them. I just went through all the settings in Tools/Options. I'm not finding anything to explicitly direct the use/non-use of the ResX files. So, I pulled up help found I should set the Localizable flag to false. All my forms have it off.
If I interpret the use of Localizable correctly, the ResX file will always get used. The Localizable causes the creation of additional RexX files, one for each appropriate language.
Which only leaves something in the assemblies. Let me ask this:
If I have components A, B and C in MyDLLs (version 1) and they are in use in the solution.
I add a component D. To prevent duplicate components when Add/Remove Toolbox Items is used, I remove v1 of A, B and C from the Toolbox. I then reference MyDLLs and add A, B, C and D back into the toolbox but they are all now Version 2.
Will this reset components A, B and C in my solution?
|
|
|
|
|
dbetting wrote:
Will this reset components A, B and C in my solution?
No. The toolbox is merely a container for components, controls, and other snippets. Nothing really happens until you add one of those to your project, when the component reference is added to your container and the containing assembly is added to your project references, if necessary.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
how would one generate a listbox with items from his dataset?
for example.
I have a dataset with a table Movie and a column Title.
I'm using oleDbDataAdapter1 on a access database.
I want my list box to contain all the titles from that database.
I don't know much about sql yet. so pardon my ignorance
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
See the ListControl.DataSource property documentation in the .NET Framework SDK, from which the ListBox derives. This has nothing to do with SQL itself. Once you get a DataSet that contains your data from a database (or other OLE DB or ODBC source), then it's simple:
listBox1.DataSource = ds;
listBox1.DataMember = "MyTable";
listBox1.DisplayMember = "Name";
listBox1.ValueMember = "ID"; You can set the last three initially after you instantiate the ListBox (called listBox1 in this simple example). You can set DataSource at any time when you get data to fill the ListBox . You do not have to re-create it or anything, just re-assign a new DataSet (or other data source, like an array or a collection - anything that implements IList or IListSource ).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks for your help that helped alot. I appreciate it.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
One quick question.
I used a combobox instead but anyway i have my values in there.
I can't figure out what the actually texts value gets stored as.
for example.
I have
A
B
C
If i select B I have MessageBox.Show(comboBox1.SelectedText);
I thought this would show the text that was selected but all i get is System.Data.blah.blah blah
Any idea why this is?
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Depending on the value of ComboBox.DropDownStyle , the SelectedText is not what you want to use. If DropDownStyle is set to ComboBoxStyle.DropDownList , then use the SelectedIndex to get the index and use ComboBox.Items[index] to get the item you want.
If you're getting a System.Data.DataRowView (or similar), then you aren't binding your ComboBox to your DataSet correctly. The code I wrote above still works the same, but I can't help you unless you post the code you're using to initialize your ComboBox .
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I figured it out.
All i needed to do was comboBox1.Text
I forgot about the text option.
that way i can say
oleDbDataAdapter1.SelectCommand.Parameters["Title"].Value = comboBox1.Text;
thanks for the help
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
I have a question.
I have the listbox showing all my items now. and have it linked to the database and it is removing the items. However. When i remove the item i want the listbox to be updated. its not doing it though.
private void removebutton_Click(object sender, System.EventArgs e)
{
oleDbDataAdapter1.Fill(dataset);
try
{
string strSQL = "DELETE FROM Movie WHERE Title = '" + comboBox1.Text.ToString() + "'";
oleDbDeleteCommand1.CommandText = strSQL;
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.Connection.Open();
oleDbDeleteCommand1.ExecuteNonQuery();
oleDbDeleteCommand1.Connection.Close();
MessageBox.Show(comboBox1.Text.ToString() + " has been removed");
oleDbDataAdapter1.Update(dataset);
}
catch (Exception ex)
{
MessageBox.Show("Not found");
MessageBox.Show(ex.ToString());
}
}
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
You updated the database using the changes in the DataSet (known as a DiffGram). As I mentioned previously, re-assign the new DataSet to the DataSource property (leaving the other properties untouched - they do not need to be changed).
Note, though, that if you remove an item from the ListBox - which removes the item from the DataSet - then why bother rebinding? It's already removed from the ListBox . This is a big waste of time, unless you know the database may be updated by other clients.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Heath thanks for your help. I'm just not getting it for some reason. I have read what you typed several times and its just not clickin for some reason.
From what I gather you do whatever you want to with the dataset like i'm doing, then when your done messing around with it you then update it with
OleDbDataAdapter1.Update(dataset);
so based on what i'm gathering from you. I type the following to refesh my comboBox
comboBox1.DataSource = dataset; // update the comboBox
if that is the correc then for some reason its not working.
private void removebutton_Click(object sender, System.EventArgs e)
{
try
{
string strSQL = "DELETE FROM Movie WHERE Title = '" + comboBox1.Text.ToString() + "'";
oleDbDeleteCommand1.CommandText = strSQL;
oleDbDataAdapter1.DeleteCommand = oleDbDeleteCommand1;
oleDbDeleteCommand1.Connection = oleDbConnection1;
oleDbDeleteCommand1.Connection.Open();
oleDbDeleteCommand1.ExecuteNonQuery();
MessageBox.Show(comboBox1.Text.ToString() + " has been removed");
oleDbDataAdapter1.Update(dataset); oleDbDeleteCommand1.Connection.Close();
}
catch (Exception ex)
{
MessageBox.Show("Not found");
MessageBox.Show(ex.ToString());
oleDbDeleteCommand1.Connection.Close();
}
oleDbDataAdapter1.Fill(dataset);
comboBox1.DataSource = dataset;
}
sorry Just not understanding this
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
For one, if the item is removed in the data-bound control - which removes it from the DataSet bound to the control - and you update the database, why would you need to update the data-bound control? Think about it - the item is already removed. Why waste the time re-binding when the information is already in sync?
Second, if you want to assign the same DataSet to the DataSource (it's still the same instance), you must reset the binding by first setting DataSource to null then back to the DataSet instance.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Ok i got it working.
I did used the clear() on the dataset and then refilled it. I'm glad Code Project is around and folks like yourself that give me a hint but not the straight answer. That way I'm forced to learn it.
thanks again,
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Has anyone came up with a solution of how to change the toolbars default color? I noticed there is a toolbar.defaultbackcolor; but that just shows its value. How do you set it. I also read on msdn something about.
private virtual Color BackColor {get; set;} but thats pretty much all it says or i'm not getting it one. I'm assuming you have to override it somehow. I have looked around i see premade classes and all but id really like to know how its done instead of just having someone elses premade stuff. Is it highly complex? if not could someone post a simple example?
Win32newb
"Making windows programs worse than they already are"
|
|
|
|