|
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"
|
|
|
|
|
ToolBar.BackColor is overridden and attributed both with the BrowsableAttribute and EditorBrowsableAttribute to hide it from designer controls (like the PropertyGrid) and source editors. Why? Because it's not used. If you want to change the background color of the ToolBar , you have to handle all the Win32 notification messages by overriding WndProc (experience with Windows messaging will be helpful) or use a third-party toolbar, from which you'll get a lot more options than the simple one included in the .NET FCL (Framework Class Library).
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
Thanks. I check in on it I knew there had to be a reason it wasn't implemented. Thanks again.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Ok let me explain what i'm trying to do first off
I have 1 form called form1 then i have 2 user controls add and delete.
I have a menu put on forms1 cause i'm using it as my main interface.
I have on the menu a item add record and then remove record.
when i hit the add record i want to bring to focus the add();
and the same thing for if i hit delete i want delete() to bringtofront.
But I don't want numerous instances of the same thing so how do i kill the instances based on the menu selection?
I never want form1 to be killed i just want it to loose its focus based on the menu selection.
So if i have in form1
private database.Add objSearch_notfound;
and under the addmenu
objSearch_notfound = new Add();
Controls.Add(objSearch_notfound);
objSearch_notfound.BringToFront();
objSearch_notfound.Show();
I understand this will bring the add to focus.
I also understand that
Controls.Remove(this);
this.hide();
if put on a button in the add() will kill the add() focus.
But how do i make it do this on the menu?
cause when i click the menu then the add() loses focus so if i did
addmenu()
controls.Remove(this);
this.hide();
it will kill the form1
I thought i could in form1 do this but it doesn't work
Controls.Remove(objsearch_notfound)
objsearch_notfound.Hide();
any clues would be great and hope this is clear. It's kinda hard to explain without showing you the source code.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
Showing and hiding user controls or forms will not make dispose of them. Just use a couple of fields in your class to keep a reference to them, the same as the designer does when you design your form:
public class MyForm : Form
{
private Add addControl;
private Delete deleteControl;
public MyForm()
{
addControl = new Add();
deleteControl = new Delete();
}
private void addMenu_Click(object sender, EventArgs e)
{
Controls.Remove(deleteControl);
Controls.Add(addControl);
}
private void deleteMenu_Click(object sender, EventArgs e)
{
Controls.Remove(addControl);
Controls.Add(deleteControl);
}
} This is a simple example, but hopefully gives you some idea that you don't dispose of controls when showing/hiding them, or adding/removing them from the parent's Controls collection property.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
First off thanks this worked perfectly. Well kinda don't know if its just forgotten in your snippet or i'm doing something wrong. In any event. If you don't do addcontrol.BringToFront(); then it simply overlays the other window looking like crap Just something i seen when playing around with.
Thanks again for the help.
but the object ref works great i thought that was how it was done but just couldn't figure it out. thanks again.
Win32newb
"Making windows programs worse than they already are"
|
|
|
|
|
It wasn't "forgotten". Remember, this was sample code. Don't expect a complete solution from sample code: nothing is truly learned then.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
One approach that you could take (if it fits in with your application design) is to make the main form an MdiParent and make the other forms MdiChild forms.
When either choice is clicked the first step each option would take is to issue a CloseAllChildren() call. The logic for the parent form for this method is as follows:
private void CloseAllChildren()
{
System.Windows.Forms.Form[] myChildren = this.MdiChildren;
foreach (Form child in myChildren)
{
child.Close();
}
return;
}
If you children have any valuable resources that they should release, you can add a trap on the Closing Event.
public void Form1_Closing(object sender, System.EventArgs e)
{
... release resources ...
... if user did not save see if they really want to throw
awway their work
e.CloseCancel = true;
}
___________________
Forgoing antagonism and separation, one enters into the harmonious oneness of all things. Lao Tzu
|
|
|
|