|
I have a tabpage and a panel inside this tabpage. When I insert anything to panel I want to center tabpage's scrollbar because I insert anything center of this tabpage but TabPage Scrollbar place on left.Can you explain that how I code that???
another how can I reach height of scrollbar(tabpage's autoscroll)????
-- modified at 5:28 Saturday 28th July, 2007
|
|
|
|
|
If any one has practical ideas for IT engineering graduation project please send me it and I will be very thankful for him
my e-mail is michaelqog_71@hotmail.com
|
|
|
|
|
Practical, depends on your skills... You might try searching the forums for other people asking the same question, and then re-consider this post.
Hogan
|
|
|
|
|
Quit asking the same old question all the time. Use your brains
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
I have a database and I figured out how to store data but i can't edit anything.
This is a part of my code:
<br />
private void button1_Click(object sender, EventArgs e)<br />
{<br />
MyDataSet.MyTable.AddMyTableRow(textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text);<br />
MyTableAdapter.Update(MyDataSet.MyTable);<br />
toolStripProgressBar1.PerformStep();<br />
MessageBox.Show("Update Complete", "Update Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);<br />
} <br />
<br />
private void button5_Click(object sender, EventArgs e)<br />
{<br />
DataTable dtedit = MyDataSet.MyTable;<br />
DataRow dr11 = dtedit.NewRow();<br />
dr11["Field1"] = textBox6.Text;<br />
dr11["Field2"] = textBox7.Text;<br />
dr11["Field3"] = textBox8.Text;<br />
dr11["Field4"] = textBox10.Text;<br />
dr11["Field5"] = textBox11.Text; <br />
dr11.AcceptChanges();<br />
MyTableAdapter.Update(MyDataSet.MyTable);<br />
}<br />
|
|
|
|
|
Hi,
I'm trying to receive windows messages to notify my program of when it has been deactivated or activated. I've used the following class, and a basic windows form to try it out:
public class AppMessageFilter : IMessageFilter
{
private const int WM_ACTIVATEAPP = 0x001C;
public bool PreFilterMessage(ref Message m)
{
if (m.Msg == WM_ACTIVATEAPP)
{
//Lost focus:
if ((int)m.WParam == 0)
{
MessageBox.Show("Deactivated");
}
//Gained focus:
else
{
MessageBox.Show("Activated");
}
}
return false;
}
}
And....
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Application.AddMessageFilter(new AppMessageFilter());
}
}
However, this does not work. I've tried different windows messages (e.g. WM_ACTIVATEAPP and WM_ACTIVATE), but neither get filtered in the PreFilterMessage method when I switch from my form to another application (e.g. internet explorer or another window). I'm only using the MessageBox parts to test it works - i've also tried omitting these and testing to see if breakpoints are reached.
I've tried this on both Windows 2000 and Vista 64. Any ideas where i'm going wrong?
Thanks
James
|
|
|
|
|
I don't know what's wrong here, but I copied your code and I don't get any of these messages, too.
regards
modified 12-Sep-18 21:01pm.
|
|
|
|
|
Hi!
I am using to read and write to a specific file.
In The beginig i am doing this:
if (File.Exists("Delete_Items.txt"))
{
bfs = new FileStream("Delete_Items.txt", FileMode.Open);
StreamReader m_streamReader = new StreamReader(bfs);
textBox2.Text = m_streamReader.ReadLine();
m_streamReader.Close();
bfs.Close();
}
So i am reading from the file and then free every thing, but then i am tring to do ub another function this:
FileStream bfs = null;
if (File.Exists("Delete_Items.txt"))
{
File.Delete("Delete_Items.txt");
File.Create("Delete_Items.txt");
bfs = new FileStream("Delete_Items.txt", FileMode.Append);
StreamWriter m_streamWriter = new StreamWriter(bfs);
m_streamWriter.WriteLine(textBox2.Text);
m_streamWriter.Close();
bfs.Close();
}
I want to overrite the data and so i am deleting the file before, and i get an exception explainig me that the file is being used by another process, and this is although i freed it.
What is wrong??
Thanks
|
|
|
|
|
Not sure if it's the whole problem, but try disposing the FileStream and the StreamReader instead of just closing them. And you don't need to delete the file before writing to it, use the FileMode that overwrites. (Don't remember off hand which it is, but intellisense tells you.)
But look at the context that the code runs in, you're not doing multithreaded calls to these methods are you?
|
|
|
|
|
Hi,
good question, I will surprise you.
First of all, you should watch the line numbers: when building a debug version,
the Exception normally shows line numbers (at least for your code, not for
system libraries).
My guess is the line number points to File.Delete
Yes you can not delete your own file, because someone else is accessing it.
That someone is trying to help you somehow; I dont know who it is, here are the
usual suspects:
- some anti-virus tool
- some indexing utility, say Google Desktop Search
such tools are always interested in the latest files !
Remedy: make a method to delete a file; the method should:
- use a for loop (say 5 times), inside it:
- use try-catch,
- in the try part File.Delete and return
- in the catch part: Thread.Sleep(1000) followed by
if (last iteration) File.Delete
This code tries to delete 6 times, with 1 second interval; the last one
throws to the caller, the first 5 just make you wait.
The surprise is: this is exactly what Windows Explorer is doing, when
it cannot delete at first, it retries 5 times before telling you it failed !
Good luck !
|
|
|
|
|
try
using ( StreamWriter m_streamWriter = new StreamWriter(bfs))
{
m_streamWriter.WriteLine(textBox2.Text);
}
Because StreamWriter inherits IDisposable, you can have the using statement. After the last }, the object is closed and disposed properly.
Hogan
|
|
|
|
|
I believe your problem lies with these two lines:
File.Create("Delete_Items.txt");
bfs = new FileStream("Delete_Items.txt", FileMode.Append);
File.Create() returns a FileStream to the file you just created -- this FileStream needs to be closed before you can try to open it again for appending, or just use the FileStream that you just made.
So you'd change it to:
File.Create("Delete_Items.txt");
bfs.Close(); //Added
bfs = new FileStream("Delete_Items.txt", FileMode.Append);
OR
bfs = File.Create("Delete_Items.txt");
-Phil
|
|
|
|
|
Hello experts,
There's something that has been bothering me for quite some time now...
Is there a performance difference between the following two implementations?
for (...)
{
int x = ...;
}
int x;
for (...)
{
} In the first case, is x getting allocated for every step of the loop?
Or does .NET knows to allocate it once, and use it again and again?
Thanks in advance,
Shy.
|
|
|
|
|
I haven't looked at the IL, but I'm pretty sure you're creating and dumping a new integer every interation in your first example. And therefore, yes, it performs worse.
|
|
|
|
|
I see...
Is it the same for reference types?
|
|
|
|
|
Hi,
please read my other reply first.
if it is:
string x="aha";
for (...) {
string y=x;
}
then again it wont make a difference, since y=x simply copies a reference,
it does not create an object; it has the same cost as int y=x;
And again, if the compiler notices x can not change during the loop, it
should and would move the statement outside the loop.
|
|
|
|
|
Exactly the answer I was looking for!
Thanks!
|
|
|
|
|
Hi,
you should not believe everything they tell you.
int is a value type, it probably gets "allocated" on stack (meaning the stack pointer
gets lowered a bit more when you enter this method to reserve a spot for it),
this has zero cost.
(the probably means, maybe the int variable does not need storage, the JIT might
decide to keep it in one of the CPU registers, but I am not relying on this)
Anyway, there is no "new", no object, and no garbage collection involved.
both code snippets could and should result in exactly the same MSIL code;
and I would be very surprised if you can measure the slightest difference in
execution time (which would hint a compiler inefficiency, not an inherent difference
between both code snippets).
|
|
|
|
|
I stand corrected, both of these...
public void Inside() {
for (int i = 0; i < 1000; i++) {
int x = i;
}
}
public void Outside() {
int x;
for (int i = 0; i < 1000; i++) {
x = i;
}
}
decompile to something similar to this...
public void Outside() {
int num1;
int num2;
for (num2 = 0; (num2 < 1000); num2 = (num2 + 1)) {
num1 = num2;
}
}
The compiler does you the favor of moving your variable outside the loop where it belongs.
|
|
|
|
|
|
Time it through the PerformanceCounter class for large iterations in the for loop and compare results...
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
For what its worth, I just ran a test and got the following results. It looks like it doesn't matter for something this small.
Inside the loop took 552645639 ticks.
Outside the loop took 549520699 ticks.
The test code:
long timeIn = 0;<br />
long timeOut = 0;<br />
<br />
long l = System.DateTime.Now.Ticks;<br />
for (long x = 0; x < 10000000000; x++)<br />
{<br />
int i = 1;<br />
i++;<br />
}<br />
timeIn = System.DateTime.Now.Ticks - l;<br />
<br />
l = System.DateTime.Now.Ticks;<br />
int i2;<br />
for (long x = 0; x < 10000000000; x++)<br />
{<br />
i2 = 1;<br />
i2++;<br />
}<br />
timeOut = System.DateTime.Now.Ticks - l;<br />
<br />
MessageBox.Show("Time In: " + timeIn.ToString() + Environment.NewLine + "Time Out: " + timeOut.ToString());<br />
Hogan
|
|
|
|
|
Indeed, I found the same thing last week.
|
|
|
|
|
So the measured difference is less than 1% which is I guess well below
your measurement accuracy: you are measuring elapsed time (good) over
a long period (50 sec, good), but circumstances vary: there are hundreds
of threads in an idle system, watching each and every part of your machine,
there are disk transfers with DMA, there is a varying amount of Ethernet
traffic including broadcast messages you are not interested in, etc etc.
So my first impression is the execution times are the same.
What you could do is reduce the loop count by a factor of 100, run it
100 times, and observe the distribution of the 100 timing results.
The disappointment is neither the C# compiler nor the JIT compiler was
smart enough to recognize the entire loop body could and should be moved
outside, and then the loop is without subject; so it should have been
hundred ticks at most !
On a non-CLR language (such as good old C) it takes quite some tricks
to prevent the compiler from throwing it all out, and still get an
accurate measurement !
|
|
|
|
|
Hi,
This is related to the formatting, not the topic, of your message.
I am preparing an article on copying code snippets from a CodeProject message board to
Visual Studio; seems there are no problems when the browser used is FireFox, Safari, ...
but often problems arise when using Internet Explorer.
One of the factors is the tags that are present inside the < PRE> </PRE> block.
In your message the lines are separated by <br> tags; most other messages have
just regular newlines.
Could you please tell me how you get that, i.e. what tools you use, and how you go
about it. Thanks in advance.
|
|
|
|