|
In the MouseDown/Up event, get the x and y coordinates of the cursor. From this you can determine which node the mouse is on by using the GetNodeAt() method. If you want to know if a mouse has selected the tree view item label or its icon.
I hope this helps.
Human beings were not meant to sit in little cubicles staring at computer screens all day, filling out useless forms and listening to eight different bosses drone on about about mission statements. -- Peter Gibbons
|
|
|
|
|
Thanks very much. That sorted it out for me and I'm generating a context-specific menu.
|
|
|
|
|
Hello!
In C++ one could indent listview items very easily: lvi.iIndent = 1. Now, how can we do the same in C#?
I've read something about a ListViewItem.IndentCount and ListViewItem.NumIndents properties, but my compiler doesn't know these members... All other things work quite nicely (lvi.ImageIndex, lvi.SubItems.etc.).
Thanks in advance and best regards
Dominik
_outp(0x64, 0xAD);
and
__asm mov al, 0xAD __asm out 0x64, al
do the same... but what do they do??
(doesn't work on NT)
|
|
|
|
|
I've been battling this for a long time, and i managed to get it working with the Icon class, but due to recent changes in a program I'm working on, I now have to keep all my icons as Image class members. This gives me the black border around alpha transparent pixels in my icons. This is the code i'm using:
For the API:
<br />
private static uint SHGFI_ICON = 0x100;
private static uint SHGFI_LARGEICON = 0x0;
private static uint SHGFI_SMALLICON = 0x1;
[DllImport("Shell32.dll")] <br />
<br />
private static extern int SHGetFileInfo( string pszPath, uint dwFileAttributes, ref SHFILEINFO psfi, int cbfileInfo, uint uFlags); <br />
<br />
private struct SHFILEINFO <br />
{ <br />
public IntPtr hIcon; <br />
public int iIcon; <br />
public int dwAttributes; <br />
public string szDisplayName; <br />
public string szTypeName; <br />
} <br />
<br />
public enum FileIconSize <br />
{<br />
Small,
Large
}<br />
<br />
public static Image GetFileIcon(string fullpath, FileIconSize size) <br />
{<br />
SHFILEINFO info = new SHFILEINFO();<br />
<br />
uint flags = SHGFI_ICON;<br />
if (size == FileIconSize.Small) <br />
{<br />
flags |= SHGFI_SMALLICON;<br />
}<br />
<br />
int retval = SHGetFileInfo(fullpath, 0, ref info, System.Runtime.InteropServices.Marshal.SizeOf(info), flags);<br />
if (retval == 0) <br />
{<br />
return null;
}<br />
<br />
System.Drawing.Icon icon = System.Drawing.Icon.FromHandle(info.hIcon); <br />
<br />
System.Windows.Forms.ImageList imgList = new ImageList();<br />
imgList.ColorDepth = ColorDepth.Depth32Bit;<br />
imgList.ImageSize = icon.Size;<br />
imgList.Images.Add(icon);<br />
return imgList.Images[0];<br />
} <br />
Actual working code on a Windows Form:
<br />
Graphics g = Graphics.FromHwnd(this.Handle);<br />
g.FillRectangle(System.Drawing.SystemBrushes.ControlDark,20,50,32,32);<br />
Image ico;<br />
ico = API.GetIcon(ofd1.FileName, API.FileIconSize.Small);<br />
<br />
<br />
g.DrawImage(ico, 20,50);<br />
can anyone tell me what i'm doing wrong? i thought i had taken care of all the little possible ways to screw it up, such as converting it to a bitmap...
|
|
|
|
|
hi, how i can remove by code the checkbox from one node of the treeview nodes cause i want to make a treeview with one root and sub nodes and checkboxes beside the subnodes only without a checkbox beside the root >>>
Thanks alot
Hamody
|
|
|
|
|
The checkboxes apply for the entire treeview as such, and hence you would have to validate it in your code.
In tvwList_MouseMove() event, use eventargs to find tvwList.GetNodeAt(e.X, e.Y) to get the current node, and disable the checkbox there. (nod.Checked = false;)
|
|
|
|
|
Is there a way to change the readonly color of a property grid?
My propertygrid is completely readonly and I would like all of the data to be displayed in black text to make it more visible. I have tried setting the ViewForeColor property to black, but it still displays as gray. However, I can change the ViewForeColor property to Red (or another color) and it will change.
It seems to be muting whatever color you put in there to a lighter shade to indicate readonly. So by setting it to red, I get a lighter shade of red for readonly properties. By setting it to black, I get gray for readonly properties.
Maybe there is a way to disable this "muting" of the readonly colors?
Any suggestions would be appreciated.
Thanks.
--Jill
|
|
|
|
|
Hi, I'm working with a application and I've added support for scaling window so it can fit different resolution.
One control I'm having problem with is the TabControl. I've used the fixed style and set the ItemSize (had to do that to get the correct look with horizontal text). But now the control refuses to change it's ItemSize when I'm scaling the window.
Anyone know of a way to change the ItemSize property dynamically on a tabcontrol?
Regards
/Mike
|
|
|
|
|
this.tabControl1.ItemSize = new Size(Convert.ToInt32(this.Width * 0.1), Convert.ToInt32(this.Height * 0.1));
(Just a random number to have this, The tabcontrol is in Fixed Size mode) and have used the above code in Resize event.
|
|
|
|
|
HI
This is the format of my text file
i have to show data from text file to List View
a.txt
--------
1,2,3,4,5,6,7,8
9,10,11,12,13,14,15,16
17,18,19,20,21,22,23,24
Here 1 will come in one coulmn and 2 will come in another coulmn
In my winform there are 8 Columns in ListView
it should display all the contents
code needs
regards
sanjeev
|
|
|
|
|
You might try something like this:
using(StreamReader sr = new StreamReader("a.txt"))
{
string line = sr.ReadLine();
while (line != null)
{
ListViewItem newItem = new ListViewItem();
string[] subItems = line.Split(',');
for(int i=0;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i]);
listview.Items.Add(newItem);
string line = sr.ReadLine();
}
}
</code>
/cadi
24 hours is not enough
|
|
|
|
|
hi
your code is working fine
but in first column it takes blank space
it starts print after first column can u change ur code
regards
sanjeev
|
|
|
|
|
Hi!
to be honest, id did not test the code... i just wrote in in the editor...
should be like this:
string[] subItems = line.Split(',');
if (subItems.Length > 0)
{
ListViewItem newItem = new ListViewItem(subItems[0].Trim());
for(int i=1;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i].Trim());
}
this should work better (not testet too )
/cadi
24 hours is not enough
|
|
|
|
|
Hi
Thanks for your answer
Its working fine
StreamReader sr = new StreamReader("job.txt");
string line = sr.ReadLine();
line=line.Trim();
while (line != null)
{
ListViewItem newItem=null;
string[] subItems = line.Split(',');
if (subItems.Length > 0)
{
newItem = new ListViewItem(subItems[0].Trim());
for(int i=1;i<subItems.Length;i++)
newItem.SubItems.Add(subItems[i].Trim());
}
lbo_BD_historyEntry.Items.Add(newItem);
line = sr.ReadLine();
}
Again i have another question I have to write 10 lines in job.txt after 10 lines it will copy all the contents to oldjob.txt
and job.txt will delete all the contents it will again start storing new 10 lines. Job.txt has limitation of storing only 10 lines.
oldjob.txt will store all the contents
could u pls tell me
one more question i have
suppose my column name is name i have to search name in name column
name is suppose sanju
it will search from oldjob.txt and job.txt from both the files
and will display the result in listview
could u pls tell me how to make for optimazation purpose
regards
sanjeev
|
|
|
|
|
Hi Sanjeev,
first one comment to your code. You should either use a using block around the usage of the StreamReader or at least close it after use.
I hope the code below gives you some idea on how you could do it.
The performance will decrease by every entry made to "oldjob.txt" since you can only search seqentially. If you exceed several thousand lines you should move to some database driven model.
using System;
using System.IO;
using System.Collections;
namespace CodeProject
{
public class AppendAndMove
{
private const int LIMIT = 10;
private int m_LinesWritten = 0;
private string m_File1 = @"job.txt";
private string m_File2 = @"oldjob.txt";
public AppendAndMove()
{
if (File.Exists(m_File1))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
while (sr.ReadLine() != null)
this.m_LinesWritten++;
}
}
}
private void MoveContent()
{
using(StreamWriter sw = new StreamWriter(this.m_File2,true))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
string line = sr.ReadLine();
while (line != null)
{
sw.WriteLine(line);
line = sr.ReadLine();
}
}
}
File.Delete(this.m_File1);
}
public void AddLine(string line)
{
using(StreamWriter sw = new StreamWriter(this.m_File1,true))
{
sw.WriteLine(line);
m_LinesWritten++;
}
if (m_LinesWritten == LIMIT)
{
MoveContent();
m_LinesWritten =0;
}
}
private string[] FindValueInFile(string fileName,int columnIndex, string value)
{
ArrayList result = new ArrayList();
if (File.Exists(fileName))
{
using(StreamReader sr = new StreamReader(fileName) )
{
string line = sr.ReadLine();
while (line != null)
{
string[] columns = line.Split(',');
if (columns.Length > columnIndex)
{
if (columns[columnIndex] == value)
{
result.Add(line);
}
}
line = sr.ReadLine();
}
}
}
return (string[]) result.ToArray(typeof(string));
}
public string[] FindValue(int columnIndex, string value)
{
ArrayList result = new ArrayList();
result.AddRange(FindValueInFile(this.m_File1,columnIndex, value));
result.AddRange(FindValueInFile(this.m_File2,columnIndex, value));
return (string[]) result.ToArray(typeof(string));
}
[STAThread]
static void Main()
{
AppendAndMove testClass = new AppendAndMove();
System.Text.StringBuilder sb = new System.Text.StringBuilder();
Random rnd = new Random();
for(int i=0;i<100;i++)
{
sb.Length=0;
for(int t = 0;t<8;t++)
{
sb.Append(rnd.Next(1,100));
if (t != 7)
sb.Append(",");
}
testClass.AddLine(sb.ToString());
}
string[] foundLines = testClass.FindValue(2,"50");
foreach(string s in foundLines)
System.Console.Out.WriteLine(s);
}
}
}
/cadi
24 hours is not enough
|
|
|
|
|
Hi cadi,
Thanks for your help.
can you little bit change your code
my job.txt file is given below
-----------------------------
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
5,6,7,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
1,2,3,4,5,6,7
here in this file total rows is 15 .
If the file length is greater then 10 rows then all the previous records will appended to oldjob.txt
In your program you have created random no and stored in oldjob.txt
I want that all the previous records more then 10 lines will be copied to oldjob.txt.
File length should not greater than 10 rows or 10 lines.
If currently 5 rows to be displayed but job.txt aleardy has 10 rows. then 10 rows will be appended to oldjob.txt
can you do that
thansk again for your kind help
regards
sanjeev
|
|
|
|
|
Hi,
Job.txt can store only 10 rows suppose job.txt has 14 rows previous 10 rows will be tranferred to oldjob.txt and last foru rows will be stored in job.txt
actaullty it counts in contructor how many rows are present in job.txt
here is the code
public Form1()
{
//
// Required for Windows Form Designer support
//
if (File.Exists(m_File1))
{
using(StreamReader sr = new StreamReader(this.m_File1) )
{
while (sr.ReadLine() != null)
this.m_LinesWritten++; //total no of rows in job.txt
MessageBox.Show(this.m_LinesWritten.ToString());
}
}
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
private void button11_Click(object sender, System.EventArgs e)
{
ArrayList ob=new ArrayList();
if (this.m_LinesWritten >= LIMIT)
{
MessageBox.Show("Reached limit");
StreamReader sr = new StreamReader("job.txt");
string line = sr.ReadLine();
line=line.Trim();
int count=1;
int i;
string fileName = "temp1.txt";
while (line != null)
{
string[] subItems = line.Split(',');
ListViewItem newItem=null;
string[] subItems1 = line.Split(',');
if (subItems.Length > 0)
{
newItem = new ListViewItem(subItems1[0].Trim());
if(count>10 )
{
for( i=0;i<subItems.Length;i++)
{
newItem.SubItems.Add(subItems1[i].Trim());
ob.Add(subItems1[i].Trim());
}
}
}
if(count>10 )
{
listView1.Items.Add(newItem);
}
line = sr.ReadLine();
count=count+1;
}
int l=ob.Count;
MessageBox.Show(ob.Count.ToString());
writer = File.AppendText(@"oldjob.txt");
for(int m=0;m<l;m++)
{
writer.Write((string)ob[m] + ",");
}
writer.Close();
}
here problem is that oldjob.txt stores all in one line
here is the structure of oldjob.txt
-------------------------
6,7,8,9,10,11,13,6,7,8,9,10,11,14,
i want in this structure
6,7,8,9,10,11,13
6,7,8,9,10,11,14
can you modify the above given code
regards
sanjeev
Everything is possible
|
|
|
|
|
Hi
i would to customise the Size of a Button on a Form by mouving the Mouse(like designing Forms and Controls in VS)
an idea?
Thanks
simo
|
|
|
|
|
In runtime ?,you could override the mousedown event.
|
|
|
|
|
I am using Interop.Word.dll COM object to create a spell ckecking tool for a c# web application.
It works fine from my localhost, however when I run the application remotely from another web server I get the following exception error.
System.Runtime.InteropServices.COMException: COM object with CLSID {000209FF-0000-0000-C000-000000000046} is either not valid or not registered.
Also, I linked to my localhost from another PC (MS Word is installed in both machines) and it didn't work either.
The problem seem to be when accessing the object remotely.
Any help will be much appreciated
Thanks
Tony
|
|
|
|
|
|
if i set a my own 256 color to this.cursor, it is converted in a full black color.
How can i correctly load a 256 color in my application?
|
|
|
|
|
Hi all,
I have a simple login form to my application which displays textboxes for username, password and server (tabindexes in the order given). The user name and server values get set from the last login if they have been saved to a config file. In the form load event I check to see if the user name has been populated and if so I would like the password box to have focus e.g.
private void frmLogin_Load(object sender, System.EventArgs e)
{
if (txtUserName.Text.Length > 0)
txtPassword.Focus();
}
This doesn't work however. If I capture the result of the Focus call it returns false. Am I missing something simple here? I don't want to go the route of programatically changing the tab order.
|
|
|
|
|
or try
this.ActiveControl = txtPassword;
My Blog ^
|
|
|
|
|
|