|
anyone have any examples of creating a custom form similar to those used in applications like MS Photo Editor, Adobe Illustrator, Etc?
|
|
|
|
|
Hi, I'm trying to update an app.config file for an application. After I update the config file how do I tell the application to "refresh" the settings it read from the config originally?
example:
string val = ConfigurationSettings.AppSettings["companyName"];
// val = "My Co"
use my own routine to write the setting:
SetValue("companyName", "YourCo");
string val2 = ConfigurationSettings.AppSettings["companyName"];
// val2 = "My Co", but I want it to be "YourCo"
It's only after I close the application and restart it that I pick up the "YourCo" value.
Thanks for any suggestions,
Trevor B
|
|
|
|
|
You can make it by the xmlreader class in the i/o namespace.
|
|
|
|
|
You could add a Settings.settings file to your application.
When you edit this file in VS you have to change the Scope to User.
After that:
DateTime _date = DateTime.Today;
if (_date.Year > Properties.Settings.Default.MyDateOfSomething.Year)
{
Properties.Settings.Default.MyDateOfSomething = _date;
}
Properties.Settings.Default.Save();
Properties.Settings.Default.Upgrade();
|
|
|
|
|
How do I trap for running during development and when the system is complete.
I would like to open config files in the startup directory of the exe when the system is complete.
But during development the default directory is the bin dir.
I need to test for development and walk up ..\..\ or if not development assume the current dir is were the exe is.
Thanks.
|
|
|
|
|
During development,you can put it it same directory as the exe,and during the runtime it will be in the same directory ,and you can have that directory programtically by the user of Application.Startuppath property.
|
|
|
|
|
You can get the full path of the exe from Application.ExetutablePath.
eg.:
<br />
System.IO.FileInfo fi=new System.IO.FileInfo(Application.ExecutablePath);<br />
<br />
string exedir=fi.DirectoryName;<br />
|
|
|
|
|
From my web service client I would like to change the default way some xml is being deserialized. WSDL.exe creates a client that deserializes this xml as an array.
The xml node in the message looks like this:
<IDs>
<id>xxx</id>
<id>yyy</id>
</IDs>
I would like to have the entire xml node returned as a string or preferably as an XmlNode object.
I understand I need to change the return type of the GetIDs call but I don’t know what I should change the attributes on the method to stop this from being converted into an array. Obviously I need to remove the XmlArrayAttribute but what do I replace it with???? There does not seem to be an "XmlNodeAttribute" to deserialize the xml ID node into an XmlNode object.
Thanks for any thoughts.
Here is the method that I do not know how to edit to get the desired results:
<br />
[System.Web.Services.Protocols . . . <br />
[return: System.Xml.Serialization.XmlArrayAttribute("IDs", IsNullable=true)]<br />
[return: System.Xml.Serialization.XmlArrayItemAttribute("id", IsNullable=false)]<br />
public string[] GetIDs() <br />
{<br />
object[] results = this.Invoke("GetIDs", new object[0]);<br />
return ((string[])(results[0]));<br />
}
This is an example of the raw soap message:
<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope>
<soap:Body>
<GetIDsResponse xmlns="http://www.tempuri.com">
<IDs>
<id>1111</id>
<id>2222</id>
<id>3333</id>
<id>4444</id>
<id>5555</id>
</IDs>
</GetIDsResponse>
</soap:Body>
</soap:Envelope>
|
|
|
|
|
I'm displaying a TreeView of an active directory domain. I want to right-click on a Node and display a context menu which has a submenu which is built depending on the type of object clicked on.
I've created a context menu but when right-clicking on an object, this code, running in the Popup event of the context menu item which displays the sub-menu:
MenuItem directoryObjectClickedOn = (MenuItem)sender;<br />
ContextMenu cm = directoryObjectClickedOn.GetContextMenu();<br />
TreeView ad = (TreeView)cm.SourceControl;<br />
DirectoryEntry aDObject = (DirectoryEntry)ad.SelectedNode.Tag;<br />
MessageBox.Show(aDObject.Name);
always gives me the previous object, not the current one.
Any idea how to get the current object?
|
|
|
|
|
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
|
|
|
|
|