|
Hi,
I am a c# newbie and I am having some problems.
I am trying to draw an image with a transparent background. I wan't to be able to draw it directly onto a form or on to a picturebox (or on top of anything in fact). However, with the code below, when the image is drawn on a form, the area that I want to be transparent is transparent, but it also makes that area of the form transparent so I can see applications behind the form through it Also when I try to draw the image on a picturebox, the pictuebox just covers it up completely.
The code I have written is as follows:
protected override void OnPaint(System.Windows.Forms.PaintEventArgs e )
{
Rectangle imgRect = new Rectangle(0,0, this.Width, this.Height);
Bitmap wibblyBit = new Bitmap(_upImage);
Graphics g = Graphics.FromImage(wibblyBit);
ImageAttributes ia = new ImageAttributes();
Color transparentColor = wibblyBit.GetPixel(0,0);
ia.SetColorKey(transparentColor, transparentColor);
g.DrawImage(wibblyBit, imgRect, 0, 0, upImage.Width, upImage.Height,
GraphicsUnit.Pixel, ia);
//Draw from the memory bitmap
e.Graphics.DrawImage(m_bmpOffscreen, 0, 0);
base.OnPaint(e);
}
Any help would be greatly appreciated.
Thanks in advance
|
|
|
|
|
I'm subscribing to the VisibleChanged event in my user control. However, that's only fired when the value for Visible property is changed from false to true. It is NOT fired when the Visible property is changed from true to false. So in otherwords, I'd like to be notified not only when control is made visible but also when it is being made invisible.
How do I achieve this without overriding the Visible property?
Thanks,
- Malhar
|
|
|
|
|
UserControl classes fire the event on either transition.
Does your user control inherit directly from System.Windows.Forms.UserControl or from another class that may be overriding the Visible property, or the Show() or Hide() methods?
Are you sure the visibility is not being set from true to true, or false to false?
--
I've killed again, haven't I?
|
|
|
|
|
Office Lineman wrote: Are you sure the visibility is not being set from true to true, or false to false?
Nope...
Just to test it out, I tried with a small example.
a) put a PropertyGrid (propertyGrid1) in form
b) put a TextBox (textBox1) in form
c) bind propertyGrid1 to textBox1
d) add a handler for VisibleChanged on textBox1
e) add following code in the handler
this.Text = textBox1.Visible.ToString()
f) Run the program
g) change the "Visible" property of the textbox1 in the propertyGrid1 to true/false. The form title never shows "false" eventhough the propertyGrid1 may show "false" for the Visible property value.
I tested my solution with "MessageBox.Show(..)" instead of "this.Text = ..." but no luck.
- Malhar
|
|
|
|
|
That's bizarre. I followed your same steps in both VS2003 (w/.NET 1.1) and VS2005 (w/.NET 2.0), and the title changes to "True" or "False", appropriately, as I set the Visible property in the property grid.
--
I've killed again, haven't I?
|
|
|
|
|
That is bizzare ... no wonder I couldn't find any documentation stating that events are suppressed when visibility is changed to false. My solution is in VS2003 (1.1) and unfortunately, cannot convert to VS05. I'll see if there something funky going on in my machine.
Thanks,
- Malhar
|
|
|
|
|
Do you have .NET 1.1 SP1 installed?
You can find out if you go to Help->"About Microsoft Visual C# .NET" and look at the version on the Microsoft .NET Framework 1.1. Mine is 1.1.4322 SP1.
This may be one of the many, many bugs[^] addressed in SP1.
--
I've killed again, haven't I?
|
|
|
|
|
I have the same BUG !?!
In fact, the event is not fire when you hide the parent like this :
userControl.Parent.Hide();
|
|
|
|
|
Hi
How i can manage grid view in net 2.0.I mean size adjastmen i have grid view with 10 rows per pages but ther problem is that size is cahage dinamicly
and is dipend from data into this row how i can make to size be sam for differnet data?
good bye
best regards
|
|
|
|
|
I don't think that you can. If you set it to display 10 rows. Then 10 rows will be displayed. The height of the grid will change if any of the text is wrapped. You could put the grid inside a div tag.
Somthing like this.
<div style="OVERFLOW:auto;WIDTH:400px;HEIGHT:500px">
datagird
</div>
"People who never make mistakes, never do anything."
<A href= 'http://toddsnotsoamazinglife.blogspot.com/'>My Blog </a>
|
|
|
|
|
Ok if i don't put 10 rows i just want size to be same for every pages how i can do that???
|
|
|
|
|
i want to add Menu>Submenu dynamically, depending upon the data i receive. till now i did :
<br />
MainMenu mnuMain = new MainMenu();<br />
<br />
MenuItem mnuFile = new MenuItem("&File");<br />
MenuItem mnuMod = new MenuItem("&Module");<br />
<br />
mnuMain.MenuItems.Add(mnuFile);<br />
mnuMain.MenuItems.Add(mnuMod);<br />
<br />
MenuItem mnuFExit = new MenuItem("E&xit", new EventHandler(mnuFExit_Click),Shortcut.CtrlX);<br />
<br />
mnuFile.MenuItems.Add(mnuFExit);<br />
<br />
foreach (string strKeyName in arrValue)
{<br />
mnuMod.MenuItems.Add(strKeyName,new EventHandler(mnuModMenu_Click));<br />
}<br />
till here it's working perfectly. now i want to add submenu to those menu i'v added dynamically. only i have the text of those menu(strKeyName), but don't have any name so can't add menuitems referring them. how can i do that?
|
|
|
|
|
You could try something like:
foreach (string strKeyName in arrValue)
{
mnuMod.MenuItems.Add(strKeyName, new EventHandler(mnuModMenu_click));
foreach (MenuItem mi in mnuMod.MenuItems)
{
if (mi.Text == strKeyName)
{
}
}
}
Obviously this assumes that the Text value of each menu item is unique. However, if you have duplicates in the menu it will confuse the user... so take it for what its worth.
-- modified at 13:42 Friday 10th March, 2006
|
|
|
|
|
ya, that's the main problem, it's will not only confuse the user but also make coding harder. and most important thing is it's not possible to go with the assumption that every text will be unique. like if i build a library system(for an instance) i may have menu like --> Book > Add ; Member > Add
now on click of both add i get that "Add", and my program can't understand which "Add' has been called? Can you give any solution?
Beside this i was trying to pass the name through variable, i've tried that in sevaral way but none worked out. if i want to pass the name through a string/array how can i do that? like :
MenuItem strMenu = new MenuItem(); //considering strMenu has some value as the name of the menu
though this code is wrong, i'v just written it to explain my query.
And Thanks for your reply
|
|
|
|
|
You could save the MenuItem s in an array:
MenuItem[] menuItems = new MenuItem[arrValue.Length];
for(int i = 0; i < arrValue.Length; i++)
{
menuItems[i] = mnuMod.MenuItems.Add(arrValue[i], new EventHandler(mnuModMenu_Click));
}
menuItems[i].MenuItems.Add("First submenu's first item", new EventHandler(...)); Just remember that if you use the same event handler, you'll have to identify in it which menu item was selected, and if you didn't save all the MenuItem references, you'll have to do it by text.
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|
|
Hi All,
I am creating a class with a Hash Table as one of its objects. I am taking Hash Table as one of its members because, i need a key value pair there.
After creating the Object, i need to serializing the object into an XML file.
Obviously, it will throw an error, as hash table cannot be serialized.
How will be able to serialize such a class then. I need the hash table inside this class object only.
Anupam Mazumdar
|
|
|
|
|
|
I try to implement drag and drop in .NET FrameWork 2.0. The code below works fine. You have to drag one node onto the other. The problem is that the exception is lost. When I call the failing function via the button everything is fine, the exception comes as expected. But when I do it from drag and drop nothing happens, the exception disappears as if handled by an external code in the FrameWork. Am I doing something wrong?
The form contains only a treeview with two nodes, and a button:
using System;<br />
using System.Collections.Generic;<br />
using System.ComponentModel;<br />
using System.Data;<br />
using System.Drawing;<br />
using System.Text;<br />
using System.Windows.Forms;<br />
<br />
namespace DragAndDropTest<br />
{<br />
public partial class Form1 : Form<br />
{<br />
private TreeNode previousTarget;<br />
<br />
private void FunctionThatFailes()<br />
{<br />
throw new ApplicationException("Something is wrong");<br />
}<br />
<br />
public Form1()<br />
{<br />
InitializeComponent();<br />
}<br />
<br />
private void treeView1_ItemDrag(object sender, ItemDragEventArgs e)<br />
{<br />
treeView1.DoDragDrop(<br />
treeView1.SelectedNode, DragDropEffects.Move);<br />
}<br />
<br />
private void treeView1_DragDrop(object sender, DragEventArgs e)<br />
{<br />
TreeNode source = e.Data.GetData(typeof(TreeNode)) as TreeNode;<br />
TreeNode target = previousTarget;<br />
ResetPreviousTarget();<br />
FunctionThatFailes();<br />
target.Text += source.Text;<br />
}<br />
<br />
private void ResetPreviousTarget()<br />
{<br />
if (previousTarget != null) {<br />
previousTarget.ForeColor = SystemColors.WindowText;<br />
previousTarget.BackColor = SystemColors.Window;<br />
previousTarget = null;<br />
}<br />
}<br />
<br />
private void treeView1_DragOver(object sender, DragEventArgs e)<br />
{<br />
ResetPreviousTarget();<br />
<br />
if (e.Data.GetData(typeof(TreeNode)) != treeView1.SelectedNode) {<br />
e.Effect = DragDropEffects.None;<br />
return;<br />
}<br />
<br />
TreeNode target = treeView1.GetNodeAt(<br />
treeView1.PointToClient(Control.MousePosition));<br />
if (target == null || target == treeView1.SelectedNode) {<br />
e.Effect = DragDropEffects.None;<br />
return;<br />
}<br />
<br />
e.Effect = DragDropEffects.Move;<br />
<br />
if (target == previousTarget) {<br />
return;<br />
}<br />
<br />
previousTarget = target;<br />
<br />
target.ForeColor = SystemColors.InactiveCaptionText;<br />
target.BackColor = SystemColors.InactiveCaption;<br />
}<br />
<br />
private void Form1_Load(object sender, EventArgs e)<br />
{<br />
treeView1.AllowDrop = true;<br />
}<br />
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
FunctionThatFailes();<br />
}<br />
}<br />
}
Gyozo Gaspar
Software Developer
|
|
|
|
|
Just a guess, but the .NET framework may contain error handling for drag and drop to prevent anything horrible from occuring; for if an exception occurred during drag and drop, you would end up corrupting cross-process OLE data transfers; the source application may think you're still trying to perform a drag and drop even though an error has occurred and the drag is not continuing.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Moral Muscle
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
How can I save .doc or .pdf file in sql database ???
Regards...
|
|
|
|
|
You can save them as the SQL Binary type if the data is less than 8000 bytes (8K). If you need to store files larger than 8kB, you could save them using the SQL Image type (which simply stores an array of bytes of length up to 2 billior or so). For more information on SQL datatypes, see MSDN's Sql data type table[^].
Once you've stored your pdf or doc files as bytes, you can then get them out of the database, write the bytes to a file, rename the file with the correct extension, and you're good to go.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Moral Muscle
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Hi all. How can I get a connectionString in web.config after I has been registed RemoteObject on IIS with .Net Remoting? Please help me!!!!!!!!!!!!!!!
-- modified at 8:58 Friday 10th March, 2006
|
|
|
|
|
Im new to using Xml with C#. I have been hacking around at one section for a day now and can't get it to work at all. Rather than confuse you with my shambles code, I will jsut explain the concept. Im also slightly confussed, or misslead with my understanding of the type deffinitions, and their methods for subtrees.
<br />
XML...<br />
<Root><br />
<MajorKey att="MAJattribute1"><br />
<MinorKey att="MINattribute1"><br />
<Value>value1</Value><br />
</MinorKey><br />
<MinorKey att="MINattribute2"><br />
<Value>value2</value><br />
</MinorKey><br />
</MajorKey><br />
<MajorKey att="MAJattribute2"><br />
<MinorKey att="MINattribute3"><br />
<Value>value3</Value><br />
</MinorKey><br />
<MinorKey att="MINattribute4"><br />
<Value>value4</value><br />
</MinorKey><br />
</MajorKey><br />
</Root><br />
Im having trouble getting it to create a nodelist to children underneath a node based on it's att (attribute) value. Also, I want to extract that attribute value into a string so "MAJattribute1" would gointo a string inside the loop for that node treversal.
Any help, or suggestions.
I have spent hours and hours reading, and cant seem to find anything to pinpoint this...only ever creating attributes indide a single node, not looping through based on the attribute value.
IM GETTING STRESSED
Regards
njc
|
|
|
|
|
Edit your post, check Ignore HTML tags in this message (good for code snippets) and then we'll be able to see what you're talking about.
The w3schools site has good XPath tutorials, but I believe @ is used to indicate that you're specifying an attribute value.
Christian Graus - Microsoft MVP - C++
"I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )
|
|
|
|
|
Hi,
Im in a situation where my set up project should install two applications ina quite mode. first i should install .net sdk and then my .net application without by a single click. Is it possible. Please help me to solve this problem.
Regards
Mukilan.P.S
|
|
|
|