|
I found the problem ...
See this link:
http://www.dotnet247.com/247reference/msgs/42/214827.aspx
Yes, that is what I found. I hadn't seen the flickering before because my
form was too small.
However, this is true. The flickering occures when the underlaying window is
switched to "layered mode". Actually it flickers even if you set alpha to
255 (fully opaque).
Switching to layered mode involves three steps.
1. Checking the os version - it has to be NT 5 or latter
2. Set WS_EX_LAYERED window style
3. SetWindowLayeredAttributes this method is not defined in user32.dll for
versions before Win2k that's why first step is necessary.
When a Windows Forms control is created it is not a layered window. And it
switches to this mode when set the opacity to some value less then 1.
So my solution is to switch to layered mode in some early stage of the form
life. As soon as the form is created before to become visible. Otherwise
we'll see the flickering.
Javier is completely correct that the layered window has to be fully
redrawn. But it goes only when the window (form) resizes. You can still
invalidate some portions of the form and it will works how ot supposed to
work.
Layered window could even show better performance in some situations.
How internaly layered windows work is all painting is redirected to
off-screen buffer and when the painting's done alpha blending is applied to
the resulting picture and the result is drawn on the screen. This of course
is done internaly in windows and it uses the video card hardware support for
alpha blending if it has any.
Becuse all winodw is double buffered Windows doesn't send WM_PAINT when the
form is moved for example or when some part of the form is uncovered. In
such cases Windows uses double buffered image.
When children control is moved on the form it updates as much as it is
necessary. So the performance hit is not so big.
Anyway, my first solution that I was planning to post involved P\Invoke and
calling all API functions necessary to switch to "layered mode", but then I
found that if one set Opacity to value less then 1 and then return it back
to 1 the form class doesn't switch to the "normal mode" and leave the window
layered.
So the easiest way to get rid if this flickering is by overriding
OnControlCreated method and adding the following two lines:
this.Opacity = 0.9;
this.Opacity = 1;
No more flickering .
Thanks a lot people !!!
|
|
|
|
|
hello
i would like insert a image in sql Data base with oledb Connection.
please help me.
vahid
|
|
|
|
|
|
i think following code will help u:
1st Step: Take pic. box
2nd Step: Take a Button and Text box to take the image, which u want to save into Database
private void btnBrowse_Click(object sender, System.EventArgs e)<br />
{<br />
OpenFileDialog ofd = new OpenFileDialog( ) ;<br />
ofd.Filter = "Image files |*.jpg" ;<br />
if ( ofd.ShowDialog( ) == DialogResult.OK ) <br />
{ <br />
txtPath.Text = ofd.FileName ; <br />
try<br />
{<br />
FileStream f = new FileStream ( txtPath.Text, FileMode.Open ) ;<br />
byte[ ] buff = new byte [ f.Length ] ;<br />
f.Read ( buff, 0, ( int ) f.Length ) ;<br />
MemoryStream ms= new MemoryStream(buff,0,buff.Length);<br />
Image i = Image.FromStream ( ms ) ;<br />
img.Image = i ; <br />
f.Close();<br />
}<br />
catch(Exception ee) <br />
{ <br />
MessageBox.Show("An error has occured.\n" + ee.Message); <br />
} <br />
}<br />
}<br />
3rd Step: Create table where take one field which will image type
CREATE TABLE [dbo].[tableName] ([img_name] [image] NULL )
ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO
<br />
string dbcon = "data source=ServerName;database=dbName;user id=sa;password=";<br />
private void linklblInsertPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)<br />
{<br />
FileStream st = new FileStream ( txtPath.Text, FileMode.Open ) ;<br />
byte[ ] buff = new byte [ st.Length ] ;<br />
st.Read ( buff, 0, ( int ) st.Length ) ;<br />
<br />
try<br />
{ <br />
using(SqlConnection conn = new SqlConnection())<br />
{ <br />
conn.ConnectionString = dbcon;<br />
conn.Open();<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = conn;<br />
cmd.CommandText = "insert into tableName(imageName) values(@pict)";<br />
cmd.Connection = conn;<br />
cmd.CommandType = CommandType.Text;<br />
cmd.Parameters.Add("@pict",buff);<br />
cmd.ExecuteNonQuery();<br />
}<br />
}<br />
catch(SqlException sqle)<br />
{<br />
Console.WriteLine(sqle.Message);<br />
}<br />
st.Close();<br />
}<br />
<br />
private void linklblShowPicture_LinkClicked(object sender, System.Windows.Forms.LinkLabelLinkClickedEventArgs e)<br />
{<br />
try<br />
{<br />
using(SqlConnection conn = new SqlConnection())<br />
{<br />
conn.ConnectionString = dbcon;<br />
conn.Open();<br />
SqlCommand cmd = new SqlCommand();<br />
cmd.Connection = conn;<br />
cmd.CommandText = "select imageName from tableName where .... ";<br />
\\here u can use track id in datatabel to select, update or delete image<br />
cmd.Connection = conn;<br />
cmd.CommandType = CommandType.Text;<br />
<br />
SqlDataReader r = cmd.ExecuteReader();<br />
if(r.Read())<br />
{<br />
byte[ ] b = ( byte[ ] ) r [ 0 ] ;<br />
MemoryStream st = new MemoryStream( ) ;<br />
st.Write ( b, 0, b.Length ) ;<br />
Image i = Image.FromStream ( st ) ;<br />
img.Image = i ; <br />
}<br />
}<br />
}<br />
catch(SqlException sqle)<br />
{<br />
Console.WriteLine(sqle.Message);<br />
}<br />
}
Thankyou
BILLAH
|
|
|
|
|
|
Hi.
What work do the throw statement, alone.
What exception it force to take place?
Best wishes
|
|
|
|
|
The throw keyword *edit*(when used by itself, alone, i.e. throw; )*/edit* can only be used within a catch block. Throw will simply throw the exception that was caught within the catch block. Last modified: Saturday, May 27, 2006 8:10:31 PM --
|
|
|
|
|
Judah Himango wrote: The throw keyword can only be used within a catch block. Throw will simply throw the exception that was caught within the catch block.
Sorry to correct you, but throw can also be used outside of a catch block. The general purpose of this is to initiate an user generated exception. E.g.
if (!File.Exists("test.txt")) {
throw new FileIOException("File was not found");
}
else {
....
}
Graham.
|
|
|
|
|
Graham N wrote: Sorry to correct you, but throw can also be used outside of a catch block.
Sorry to correct you, but the OP was talking about the throw keyword alone, that is without specifying an exception. That can only be used inside a catch block.
---
b { font-weight: normal; }
|
|
|
|
|
Perhaps I've misread what specifically the OP was asking about. But as you have said, the throw keyword without an exception can only be used inside the catch block. That of course is true.
|
|
|
|
|
I believe the original poster was talking of the throw keyword by itself, rather than throwing an exception instance:
try
{
}
catch
{
throw;
}
|
|
|
|
|
Hi.
I have used "AxInterop.ShockwaveFlashObjects.dll" in my project.
How can I handle write click on it?
There is't any mouse event for it.
Best wishes
|
|
|
|
|
Hello,
I got a weird problem with an sql string and a datetime field.
First the code:
<br />
SqlCommand myCommand = new SqlCommand("SELECT * FROM orders WHERE date = @date", connect);<br />
<br />
myCommand.Parameters.AddWithValue("@date", DateTime.Parse(listOrders.Text.ToString().Substring(0, 19)));<br />
<br />
SqlDataReader myReader2 = myCommand.ExecuteReader();<br />
<br />
while (myReader2.Read())<br />
{<br />
Messagebox.Show(myReader2["amount"].ToString() + " | " +products = myReader2["productid"].ToString());<br />
}<br />
The table orders exists of a few rows which are added for testing purposes.
Some are added by hand (so in the "show table data" window), others are added by a form with a datetime.now value.
Now the weird thing is that the query gets a result when the date of the row was added by hand, but when the date of the row was added by the other form, it doesn't get a result (so the while loop isn't executed).
I don't understand why this goes wrong?
Can somebody plz help?
Tnx!
|
|
|
|
|
So, the form doesn't insert data? Or it inserts date but not with the values you expect? Either way, it would appear to be a problem with the way that the data is inserted, not with the way it is retrieved.
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
No, it's really weird, I will give you exact copies of the values I find in the date field.
By Hand:
23/10/1986 20:24:23
Inserted data:
26/05/2006 12:39:48
So the data is EXACTLY the same (as far as I know).
That's why I cannot understand it?
|
|
|
|
|
JelleM wrote: So the data is EXACTLY the same (as far as I know).
The problem is that you don't know enough.
The dates you are looking at cuts the time after the seconds and doesn't show the milliseconds. When you compare if two dates are equal, they have to be equal down to the last millisecond. When you take the truncated date that you see and compare it to the date in the database, they will differ by a fraction of a second, but that is enough for them not to be equal.
To get the exact time you need to make the comparision work, you have to display the date with full precision so that you get the millisecons also.
As you see, identifying records by a datetime value is not a very good method. You should use an id instead.
---
b { font-weight: normal; }
|
|
|
|
|
Tnx for the reply!
But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
TNX!
|
|
|
|
|
JelleM wrote: But the thing is I don't see the milliseconds (if I show the results in the database), so they must be hidden in some way or another.
They are not so much hidden, as they are not shown. If you read the values from the database and display them using a date format that shows the milliseconds, you'll see them.
JelleM wrote: But can't I use some sort of * to add to the truncated date, so the query doesn't look at the milliseconds or something like that?
You could subtract and add a second from the time, and get the records between the times. But then the time is not unique any more...
As I said, using a datetime value to identify a record is not a very good method.
---
b { font-weight: normal; }
|
|
|
|
|
TNX!
|
|
|
|
|
I changed the date-field temporary to a string-field..
What would be the advantage of using a datetime field instead of a string-field?
TNX!
|
|
|
|
|
When ever i set the size of form more than 1036,800...its again resetting to this size only.
It seems this is the maximum size of form.
But i need big form, is there any way...Pls let me know.
|
|
|
|
|
Have you set the maximum size of the form to 1036, 800? What happens when you maximise the form?
"On two occasions, I have been asked [by members of Parliament], 'Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?' I am not able to rightly apprehend the kind of confusion of ideas that could provoke such a question."
--Charles Babbage (1791-1871)
My: Website | Blog
|
|
|
|
|
I think, there is no maximum for the size. I've tried it and it works:
this.Size = new Size(1280, 1024);
|
|
|
|
|
Hi there, my name is Ami. I am currently a student at DeVry University and am taking my first programming class! I am ready to pull my hair out because I can never get any of my programs right and I really want to understand this stuff. (by the way I'm taking C# programming online)
I have a lab that I need help with....I have to design a solution with a Main() method that holds an integer variable named seconds to which I assign a value, create a method to which you pass the value, the method displays the seconds in minutes and seconds (66 sec. = 1 min and 6 sec.)...I go there from hours and so on, if anyone could give a jump start in the right direction I would appreciate it. Thanks, Ami
Ami
|
|
|
|
|
Have you tried DateTime (And it's static members like DateTime.Parse() etc...?)?
turn it to DateTime and it will be easyer then deviding it by 60 and by 24...
|
|
|
|