|
This seems to be related to this .NET bug:
http://support.microsoft.com/default.aspx?scid=KB;EN-US;q326219
|
|
|
|
|
Hi!
I have a winows form application. The torm is set to:
this.BackColor = Color.Gray;
this.TransparencyKey = BackColor;
This works great!
On the form i have a pictureBox and i am trying to set the application to:
this.Opacity = 0.78;
But this doesn´t work. The Applications background is showing (the TransparencyKey is lost) and the form has the opacity 0.78...
Any Ideas???
|
|
|
|
|
I found a trick to handle that. Note the Bitmap.MakeTransparent.
[edit] note my image has a white background that i make transparent [edit]
class AboutForm : Form
{
Timer timer = new Timer();
double STEP = 8 / 256.0;
public AboutForm()
{
Opacity = 0;
timer.Interval = (int)(1000 * STEP);
timer.Tick += new EventHandler(timer_Tick);
BackColor = Color.White;
Size = new Size(512, 420);
ShowInTaskbar = false;
FormBorderStyle = FormBorderStyle.None;
StartPosition = FormStartPosition.CenterParent;
TransparencyKey = Color.Black;
Image i = Image.FromStream(Assembly.GetExecutingAssembly().GetManifestResourceStream("splash.png"));
Bitmap b = new Bitmap(i);
b.MakeTransparent(Color.White);
BackgroundImage = b;
SetStyle(ControlStyles.DoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
UpdateStyles();
}
protected override void OnHandleCreated(EventArgs e)
{
base.OnHandleCreated(e);
timer.Start();
}
private void timer_Tick(object sender, EventArgs e)
{
if (Opacity >= 1.0)
{
timer.Stop();
return;
}
Opacity += STEP;
STEP *= 1 / 1.01;
}
}
top secret Download xacc-ide 0.0.3 now! See some screenshots
|
|
|
|
|
How do you get the size of a file? I'm using the File class and it contains methods such us File.GetCreationTime(...) , File.GetLastAccessTime(...) , File.GetLastWriteTime(...) , File.GetAttributes(...) , etc. but there was no File.GetFileSize(...). How do I do this?
-Rafferty
|
|
|
|
|
Rafferty Uy wrote:
How do you get the size of a file?
You've got to use the Length Property[^] of the FileInfo Class[^]:
long FileSize = new FileInfo("C:\\boot.ini").Length;
Best regards
Dennis
|
|
|
|
|
You can use FileInfo Class.
FileInfo fi = new FileInfo(strFileName);
long fileSize = fi.Length;
Maqsood Ahmed
Kolachi Advanced Technologies
http://www.kolachi.net
|
|
|
|
|
I have a service that collects information from a UDP port. I would like to have a program when a user is connect that display information when the service is collecting data.
So, how can a program can be notify by a service ?
(PS.English is not my first language...)
|
|
|
|
|
There are various ways to approach this.
For example you could establish a simple TCP connection, exchange UDP packets or use Remoting. It's up to you.
www.troschuetz.de
|
|
|
|
|
Hi all,
I would like to ask a question on software design.
In C#, we can directly bind the view control (e.g. text box) with
the data get from database by the dataset object. By doing so,
it would completely eliminate the middle object layer, i.e. the relational
data is directly put onto the UI. Is this a good approach ?
For me, I will add a middle object layer in between the database layer
and the view control, so first instantiate the object by the data from the
database, then bind the object to the view control. Is this method a good practice ? If yes, why there exist the dataset class in C# ?
Thanks
|
|
|
|
|
I’m fairly new at this so these are just my thoughts don’t take them as the gospel truth.
To directly bind something like a textbox to a Sql db field would mean that the Db connection would have to permanently open. I don’t think that is usually a good idea. However an idea to “loosely” bind it might me to on creation of the form open a connection to the Db and on the onChange event from the textbox (or a submit button) throw an insert string to the db using the DataSet object. Then retier the DataSet and get a new one.
It seems kinda sloppy though.
I’d be curious to here what you think.
Ronald Hahn, CNT - Computer Engineering Technologist
New Technologies Analyst
HahnTech Affiliated With Code Constructors
Edmonton, Alberta, Canada
Email: rhahn82@telus.net
|
|
|
|
|
Hi, does anyone know how i can launch a form: new FormName().Show();
without giving the form focus?
EDIT: Better yet, is there anyway to make it so that the form cant recieve focus? I get a readonly error when I try to do this.CanFocus = false;
Thanks
- Alex
|
|
|
|
|
Does anyone know how to do this?
Can it be done using [DllImport("user32")] ?
|
|
|
|
|
CanFocus is readOnly property, You can not assign any value to it. This is the main cause of the error.
You should do as below:
you can write the below code in Form1(say)
Form2 f2 = new Form2();
f2.Show();
this.Focus();
|
|
|
|
|
Im actually not trying to shift focus to the main form, im trying to make it so that the user doesnt lose focus from the window that he is currently looking at.
How can i do that?
|
|
|
|
|
Above code results the same what you are looking for.
|
|
|
|
|
Wait so if the user is working in microsoft word for example, and this form pops up (it is used to notify the user), it wont take the focus away form microsoft word?
Because thats what im tring to achieve.
thx
|
|
|
|
|
I am pasting image in a richTextBox using clipboard.
It works fine. But I want to restore the previous clipped data.
Any clue, How to go for it? The code I am using for trial is, as below
private void PasteImg(RichTextBox richTextBox1, string imageFileName)
{
System.Windows.Forms.DataObject prevDat = new DataObject();
prevDat.SetData(Clipboard.GetDataObject());
#region Pasting the image
if("" == imageFileName) imageFileName = @"c:\JayShared\music.bmp";
Bitmap myBitmap = new Bitmap(file);
Clipboard.SetDataObject(myBitmap, false);
DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste();
}
#endregion Pasting the image
Clipboard.SetDataObject(prevDat, true);
}
|
|
|
|
|
The major problem is that the managed IDataObject and OLE clipboard functions (which support drag-n-drop) don't support nearly as much as the OLE IDataObject and related functionality. The best thing you can do is just store save the IDataObject (don't store it in a DataObject ; you could loose a lot of data) and restore it later:
IDataObject oldData = Clipboard.GetDataObject();
Clipboard.SetDataObject(); You still run the risk of losing some data for certain applications that may sink events with the OLE implementation of the native IDataObject interface. Even the Office clipboard ring, for example, can't save everything (typically when the media type is TYMED_ISTREAM or TYMED_ISTORAGE because the provider may want to provided data to stream that may no longer be available depending on the connection to an advice sink).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Dear Heath,
Thanks a lot for your reply.
I modified the function as below and tested with copying text on Clipboard before entering into the function and after execution of the function. But the test result failed for 1.TextPad 2.Notepad 3. MS Word.
I have modified the code as below.
IDataObject oldData = Clipboard.GetDataObject();
System.Windows.Forms.DataObject prevDat = new DataObject();
prevDat.SetData(oldData);
Clipboard.SetDataObject(prevDat,true);
Can anything be done further?
Or Should I modify the pasting of image in richTextBox functionality, which does not use Clipboard.
Regards,
Jay
|
|
|
|
|
I said do not store the old data in a managed DataObject . You keep it as it - as an interface reference. That has the greatest change of preserving the data that is there. Once again:
IDataObject oldData = Clipboard.GetDataObject();
Clipboard.SetDataObject(oldData);
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
It results System.Runtime.InteropServices.ExternalException : The requested clipboard operation failed. Error.
Regards,
Jay.
|
|
|
|
|
On what line? What does your code look like? Please be more specific. I can't help you if you just give me tidbits of information. Why do you think doctors want you to come in in order to diagnose problems, besides charging you money (which we don't do here, so that's even more incentive to be verbose).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am really sorry for not elaborating the scenario.
Below are the details.
Steps resulting error
1. I. Open TextPad / MS Word, II. write text III. Copy the content in the clipboard
2. I. Run the C# Application II. Call the method
3.Causes Runtime eroor at Clipboard.SetDataObject(oldData) line ;
4. Error Details :
System.Runtime.InteropServices.ExternalException : The requested clipboard operation failed.
Code :
private void PasteImg(RichTextBox richTextBox1, string imageFileName)
{
IDataObject oldData = Clipboard.GetDataObject();
#region Pasting the image
if("" == imageFileName) imageFileName = @"c:\JayShared\music.bmp";
Bitmap myBitmap = new Bitmap(imageFileName);
Clipboard.SetDataObject(myBitmap, false);
DataFormats.Format myFormat = DataFormats.GetFormat (DataFormats.Bitmap);
if(richTextBox1.CanPaste(myFormat))
{
richTextBox1.Paste();
}
#endregion Pasting the image
Clipboard.SetDataObject(oldData);
}
|
|
|
|
|
Jay Shankar wrote:
It works fine. But I want to restore the previous clipped data.
Well, I'm not sure if that's your problem but when I execute your code I get a COMException (Error HRESULT E_FAIL has been returned from a call to a COM component) after Clipboard.SetDataObject() has been called but that might be due to the .NET Framework 2.0 (no, I don't have a version 1.x installed ). Anyway. It should work fine when you replace the first two line with:
IDataObject prevDat = Clipboard.GetDataObject();
This is also how it's done in the code sample in the Visual Studio Documentation (see Clipboard.GetDataObject Method[^]). Please let me know if this hint solves your problem.
Best regards
Dennis
|
|
|
|
|
Dear Dennis,
Thanks a lot for your reply. I modified the function as par suggestion by you and Mr. Heath. But could not achieve the goal. Still trying....
Regards,
Jay
|
|
|
|