|
With that little information, no - no-one can help.
We would need a better description of the problem, and probably a small fragment of relevant code (use the "code block" widget to preserve formatting) to show us what you are doing.
Did you know:
That by counting the rings on a tree trunk, you can tell how many other trees it has slept with.
|
|
|
|
|
Windows controls appereance by default depends on selected theme in windows.You can avoid it by creating your own theme independant styles for each of them.Similar job has already been done for MFC here at cp ^.
Life is a stage and we are all actors!
|
|
|
|
|
hello every one. am trying to create Image from byte array in my page. First i create the image by System.Drawing.Image then am trying to convert System.Drawing.Image to System.Web.UI.WebControls.Image. but the compiler says "Cannot convert type 'System.Drawing.Image' to 'System.Web.UI.WebControls.Image'". So any one please help me.Thxs.
|
|
|
|
|
At first you have choosen wrong forum to post your question.You should post it to ASP.NET forum.
This article explains how to solve it and lots more.
Life is a stage and we are all actors!
|
|
|
|
|
I want to register a hotkey(for example:Ctrl+Shift+A) to do such a thing:
When I press the hotkey, I hope it will input a sentence "Hello!" at the position of current cursor in a outer active window, such as Microsoft Word,NotePad,etc.
Now I have completed the registration of the hotkey with:
[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool RegisterHotKey(
IntPtr hWnd,
int id,
uint fsModifiers,
Keys vk
);
.....
RegisterHotKey(Handle, 150, 2|4, Keys.A);
.....
private void ProcessHotkey(Message m)
{
IntPtr id = m.WParam;
string sid = id.ToString();
switch (sid)
{
case "150": SayHello(); break;
.....
}
}
.......
private void SayHello()
{
MessageBox.Show("Hello!");
}
It works well! When I press Ctrl+Shift+A ,a messagebox will say "Hello!". But how to get the current active window, and input the text to current cursor, no matter where the cursor is and which application it is in?
|
|
|
|
|
Have a look at the SendKeys class. It may be sufficient for your needs.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
I try to use this:
Process myPro = new Process();
myPro.StartInfo.FileName = @"notepad.exe";
myPro.Start();
myPro.WaitForInputIdle(1000);
SendKeys.SendWait("Hello!");
It's OK. I created this process "myPro", but how to get the process of the current active window?
can you give me the detailed code? Thanks.
|
|
|
|
|
imbiz wrote: can you give me the detailed code?
No. First of all, this isn't a "give me code" web site. People here ask specific questions, while others provide advice and suggestions.
Second, it depends on circumstances. In simple situations, the process your app launches, will become the active app with the topmost window, and hence get whatever SendKeys sends. But then, the user (or a second automation-oriented app, or any app that feels like it) may suddenly cause another window, maybe another app, to get focus. The safer way is to check using GetForeGroundWindow (which requires P/Invoke techniques), or to send a message using SendMessage, or to create real inter-process communication by adapting both applications.
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
|
|
|
|
|
Thank you! I have found the solution! I compared all the handles(Toint32) of processes with Getforegroundwindow's, but it will tell me there more than one window. I observed that just the first one is the real active window, so I use "break" to quit "foreach". It works! That's so strange.
The code:
Process mypro=null;
foreach (Process thisproc in Process.GetProcesses())
{
if (thisproc.MainWindowHandle.ToInt32() == GetForegroundWindow().ToInt32())
{
mypro = thisproc;
break;
}
}
try
{
SendKeys.Send(@"{ENTER}\begin{{}split{}}{ENTER} &= {ENTER} &= {ENTER}\end{{}split{}}{ENTER}");
}
catch (System.NullReferenceException e)
{
}
Now, if I press the hotkey Ctrl+Shift+A, it will send some strings or commands to any active window. I use this to input some fixed blocks which need to be repeated for many times.
modified on Saturday, June 5, 2010 3:47 AM
|
|
|
|
|
Hi
can anyone help with the following
i use filesystemwatcher to watch a folder and add a new entry into a listbox everytime a new file is created, there is a second listbox that duplicates whats in the first but with some code allows me to change the file name via a text box, works ok as long as the item in listbox2 is highlighted when i change text, however if the listbox updates while i'm in process of changing text it removes the highlight from the item i'm editing and crashes if i press enter to confirm new file name.
Ther error i get is no doubt due to it not knowing what index to change as none are highlighted.
So how can i get it to keep the file i am changing name of highlighted until i enter the new text.
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add(e.FullPath);
listBox2.Items.Add(e.FullPath);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;
listBox2.SelectedIndex = listBox2.Items.Count - 1;
listBox2.SelectedIndex = -1;
}
private void listBox1_Click(object sender, EventArgs e)
{
listBox2.SelectedIndex = listBox1.SelectedIndex;
}
private void listBox2_Click(object sender, EventArgs e)
{
int itemSelected = this.listBox2.SelectedIndex;
string itemText = this.listBox2.Items[itemSelected].ToString();
Rectangle r = this.listBox2.GetItemRectangle(itemSelected);
this.textBox1.Location = new System.Drawing.Point(r.X + 217, r.Y + 520);
this.textBox1.Size = new System.Drawing.Size(r.Width + 4, r.Height - 10);
this.textBox1.Visible = true;
this.textBox1.Text = itemText;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
this.listBox2.Items[this.listBox2.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
if (e.KeyChar == 27)
this.textBox1.Visible = false;
}
|
|
|
|
|
The solution is very simple.
Just store the selectedindex value in some global variable,
and keep listbox2's item selected while some new item is
added to it.
Track listbox2's CollectionChanged event and write code to make
the previously selected item (which is now not selected bcoz
new item is added to listbox2) selected using our global variable
in which we stored selectedindex of listbox2.
And ya update the global variable on following event.
private void listBox1_Click(object sender, EventArgs e)
{
listBox2.SelectedIndex = listBox1.SelectedIndex;
Global_Listbox2_selectedIndex = listBox1.SelectedIndex;
}
HTH
Jinal Desai - LIVE
Experience is mother of sage....
|
|
|
|
|
Thanks for reply, i've removed second list box as i dont think it has any use for what i want it to do.
i now use the textbox to change name of listbox1 selecteditem and i am now trying to rename the actual file with "file.move" but i'm having a problem with second part of "file.move"
private void fileSystemWatcher1_Created(object sender, System.IO.FileSystemEventArgs e)
{
listBox1.Items.Add(e.FullPath);
listBox1.SelectedIndex = listBox1.Items.Count - 1;
listBox1.SelectedIndex = -1;
}
private void listBox1_Click(object sender, EventArgs e)
{
int itemSelected = this.listBox1.SelectedIndex;
string itemText = this.listBox1.Items[itemSelected].ToString();
Rectangle r = this.listBox1.GetItemRectangle(itemSelected);
this.textBox1.Location = new System.Drawing.Point(r.X + 217, r.Y + 520);
this.textBox1.Size = new System.Drawing.Size(r.Width + 4, r.Height - 10);
this.textBox1.Visible = true;
this.textBox1.Text = itemText;
this.textBox1.Focus();
this.textBox1.SelectAll();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyChar == 13)
{
File.Move(Path.GetFullPath(listBox1.SelectedItem.ToString()), this.textBox1.Text.ToString()+".avi" );
this.listBox1.Items[this.listBox1.SelectedIndex] = this.textBox1.Text;
this.textBox1.Visible = false;
}
if (e.KeyChar == 27)
this.textBox1.Visible = false;
It renames the file ok but moves file to debug directory of my project instead of leaving it where it is and just renaming it
kenny
|
|
|
|
|
hi everone,
I want to change/apply new themes on controls of win form in C# VS 2005.
I s there any open source or any other dll ?
Thanks in adv.
|
|
|
|
|
How many times are you going to ask this question?
Nobody can answer it for you if you don't explain exactly what you want to change about the controls....
|
|
|
|
|
You've asked a similar question before.
There are some third party dll's available - see here.
My signature "sucks" today
|
|
|
|
|
He's asked a lot more times than once before...
|
|
|
|
|
How many times are you going to ask this question and ignore the answers you've been given?
|
|
|
|
|
Maybe he hasn't been given an answer that solves his particular problem, but then he ought to rephrase and elaborate on the question so that we can actually guess what he wants...
|
|
|
|
|
Yes, he has. He's also been asked question to elaborate if were not understanding his question, which he's never replied to either.
|
|
|
|
|
Dear friends,
i have some problems like
i need to create application , that "creates Database,Table,Views" and need to insert default values.
at first i have created script file which contains all the operation,
then i have Executed script with help of SMO, and everything was fine, but the SMO works only where SQL server components are installed.
is it possible to create the DB,Tables, View in any other way ??
Thank you
|
|
|
|
|
You can keep your scripts in .sql files and then execute them using ADO.Net through the code.
|
|
|
|
|
Thanks....for reply
i got info form [^]
|
|
|
|
|
Hi!!
You can execute them using the .NET Sql or OleDB connector. Something like this will work
System.Data.SqlClient.SqlConnection cnn = new System.Data.SqlClient.SqlConnection([ConnectionString]);
cnn.Open();
using (System.Data.SqlClient.SqlCommand Command = new System.Data.SqlClient.SqlCommand([query], cnn))
{
Command.ExecuteNonQuery();
Command.Dispose();
cnn.Close();
cnn.Dispose();
}
Obviously if you are going to execute a bunch of query because you're going to create all the tables, insert all the defaults and such in the same process you should use transactions. Information about how to do that can be found in the MSDN, you only need to add a couple of lines more.
Hope this helps
|
|
|
|
|
I may be having dense programmer moment, but I just spent an hour debugging something that came down to a really unexpected (by me, at least) behavior with List<> vs. array. If you create a struct with a method that modifies a member, and invoke that method on an instance of the struct that resides within an array, the array element is modified as you would expect. But if you perform the identical operation on the struct that is contained in a List<structs>, the item in the List is NOT modified. The following program illustrates this...the effect is observable in VS 9 and 10.
Does this seem correct or reasonable? It certainly doesn't adhere to one of my favorite principles of language design: the principle of least surprise!
thanks, jim
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
namespace TestByValue
{
class Program
{
static void Main(string[] args)
{
Foo[] aArray = new Foo[3];
aArray[0].Increment();
Console.WriteLine("aArray[0].x is {0} and should be {1}", aArray[0].x, 1);
Debug.Assert(aArray[0].x == 1);
List<Foo> aList = new List<Foo>();
aList.Add(new Foo());
aList[0].Increment();
Console.WriteLine("aList[0].x is {0} and should be {1}", aList[0].x, 1);
Debug.Assert(aList[0].x == 1);
}
struct Foo
{
public int x;
public void Increment()
{
x++;
}
}
}
}
|
|
|
|
|
Normally in C# most things are passed by reference so when you access the item in your list and call Increment on it you modify the actual object in the list.
However in C# structs are value types (like an Int for example) and when they are passed around what you actually get are copies. So if you had a list of Ints and you accessed them in your list you wouldn't get the actual object from the list, you just get a copy that you can do whatever you like with. If you modified the Int you'd have to actually set it back to the list to actually make any changes:
List<int> myList = new List<int>();
myList.Add(5);
myList.Add(2);
int number = myList[1];
number += 3;
myList[1] = number;
With a normal array you are actually accessing the items directly so in your case they get modified as expected, but with a generic list the array subscript operator is the same as calling a function like
int GetAtIndex(int i)
{
return theActualList[i];
}
And because the struct isn't passed by reference what you end up with is a copy of what's stored in the list and that's what you're actually modifying.
If you wanted it to work the same for both then you could simply change your struct for a class
http://msdn.microsoft.com/en-us/library/ms173109.aspx[^]
Well I hope that makes sense, it's rather late and I'm off to bed now
And I also hope I haven't made and blindingly obvious mistakes.
My current favourite quote is: Punch them in the face, see what happens!
-SK Genius
modified on Thursday, June 3, 2010 11:28 PM
|
|
|
|