|
Here is a quick example:
using System;
using System.IO;
public class test
{
[STAThread]
public static void Main()
{
test t = new test();
t.Write();
}
private void Write()
{
using(StreamWriter sw = new StreamWriter(@"C:\test.txt"))
{
sw.WriteLine("Hello Nick");
}
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
Thanks Nick.
|
|
|
|
|
HI.
I have a question regarding Datagrid and its Templatecolumn.
I am trying to populate a crosstab query result in to a Datagrid. That works fine. Now I want to add hyperlinks to all the populated values in the Datagrid.
I want to pass (1) a Id (2) column-name of that fieldvalue displayed as querystring. So my idea is to pass two values in the query string.
Hyperlink column only allows one value in the querystring.
Read lot of articles about Templatecolumn.
I don’t know how to build the Templatecolumn dynamically and how to pass two values as querystring.
Please help me in solving this problem.
HOpe you all understand my problem.
|
|
|
|
|
Your question belongs in the ASP.NET forum, since only the ASP.NET DataGrid has a TemplateColumn . Please use the forum most appropriate for your questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
I am having some trouble with this method that I want converted into c#, and being a c# novice it is taking me far longer than I would like.
At the moment it is written in c++ and its function is to set the DeviceGammaRamp given a certain int value (igamma).
Here it is...
void AdjustGamma( int iGamma )
{
HDC hDC = GetDC(GetDesktopWindow());
bool bMinus = iGamma < 0;
if( bMinus )
iGamma = -iGamma;
iGamma = min(max(iGamma, 0), 255);
if( hDC ) {
const int iNum = 256;
struct sRamp {
WORD wRed[iNum];
WORD wGreen[iNum];
WORD wBlue[iNum];
} wRamp;
if( GetDeviceGammaRamp(hDC, (LPVOID)&wRamp) ) {
for( int i = 0; i < iNum; i++ ) {
if( bMinus ) {
wRamp.wRed[i] = (255 - iGamma)*(i);
wRamp.wGreen[i] = (255 - iGamma)*(i);
wRamp.wBlue[i] = (255 - iGamma)*(i);
} else {
wRamp.wRed[i] = 65535 - (255 - iGamma)*(255 - i);
wRamp.wGreen[i] = 65535 - (255 - iGamma)*(255 - i);
wRamp.wBlue[i] = 65535 - (255 - iGamma)*(255 - i);
}
}
BOOL bRet = SetDeviceGammaRamp(hDC, (LPVOID)&wRamp);
}
ReleaseDC(GetDesktopWindow(), hDC);
}
}
There is some additional information as well, I have imported gdi32.dll sucessfully, and it looks like this...
[DllImport("gdi32.dll")]
private static extern bool SetDeviceGammaRamp(IntPtr hDC, IntPtr lpRamp);
If somebody could help me with this method then I could most certainly finish of another two that I have incompleted.
Thanks for your time
|
|
|
|
|
You may want to have a look at this[^] article by Christian Graus. The source code has an implementation of gamma correction written in C#.
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
Thanks! That was an awesome article! It really has helped me alot! I might consider implementing some other features in my program now!
Wow I'm so happy now!
|
|
|
|
|
SeaMonkey007 wrote:
That was an awesome article!
Yep! Christian is a God!
Paul Lyons, CCPL Certified Code Project Lurker
|
|
|
|
|
|
Good day all.
Using the Text property in the Form design. I created a text line with the Ampersand in the text. The designer does not display the symbol, nor does running the app.
Thank you in advance for any assistance on this problem.
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
Tony D. Abel wrote:
Using the Text property in the Form design. I created a text line with the Ampersand in the text. The designer does not display the symbol, nor does running the app.
That is correct. What displays instead is an underline on the character after the ampersand indicating that is is used as part of a keyboard shortcut (like the underlines on single characters in a menu).
If you want to display an ampersand you need to type it twice.
This & That will display as This _That
This && That will display as This & That
Does this help?
Do you want to know more?
Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.
|
|
|
|
|
Just implemented the fix.
Thanks very much Colin.
Have a great evening.
Have a great coding day.
Regards,
Tony D. Abel
|
|
|
|
|
This must have a really easy answer. I have created a tabcontrol and added five pages to it. I added an 'click' event handler to each page. But the event only fires when I click on the main part of the page, not on the tabs (labels) themselves! (The graphical representation of the tabs changes with each click, but my Click handler is never called).
Since most of each page is covered with other controls this makes it almost impossible to use.
What am I doing wrong? Is there a different click event for the labels?
|
|
|
|
|
The TabPage does not include the tab itself; that is painted and otherwise handled by the TabControl . With that in mind and looking at the TabControl events, you should notice the SelectedIndexChanged event.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hello all!
I'm attempting to create an active connection to an ftp server without any success. Passive mode works fine, but I have a vendor that will not allow passive mode connections. So I use the PORT command that specifies my IP and then the port number to use and this succeeds, but when I try to send the data, the connection is out right refused.
I'm using FTPClient.cs which was posted on this site (I used *'s instead of the IP address at my company)
private Socket createDataSocket()
{
this.sendCommand("PORT *,*,*,*,7,130");
if ( this.resultCode != 200 ) throw new FtpException(this.result.Substring(4));
Socket socket = null;
IPEndPoint ep = null;
try
{
socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
ep = new IPEndPoint(Dns.Resolve("*.*.*.*").AddressList[0], ((7 << 8) + 130));
socket.Connect(ep);
}
catch(Exception ex)
{
// doubtfull....
if ( socket != null && socket.Connected ) socket.Close();
throw new FtpException("Can't connect to remote server", ex);
}
return socket;
}
I then use the STOR command to write the file name on the server, which it completes, but then the data connection is refused.
Any thoughts?
|
|
|
|
|
How do you draw on the main menu bars background? Not the actual menu items themselves but the entire menu bar.
|
|
|
|
|
Ask in the ASP.NET forum, which is specific for ASP.NET-related questions.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|
|
Hi,
I have an object that has two events. I need to serialize this object, and somehow store the hooked-up event handlers that these events have. I can't just serialize the object with the events or a lot of other stuff will get serialized too, so I need to save the methods that are hooked up to these two events somehow.
Does anyone have a good approach to this? I've tried many things, but with no luck. Thanks in advance.
|
|
|
|
|
hello, I just want to write my own Regedit in C#, just start developening it for windows xp and then move to Windows CE .NET, but remaining in the contest of the thread, I saw that Registry's API are not implemented as method, so I think I shall use P-invoke?? my question is :
in C I've got
<br />
LONG RegOpenKey(<br />
HKEY hKey,<br />
LPCTSTR lpSubKey,<br />
PHKEY phkResult<br />
);<br />
I can do:
<br />
[DllImport("advapi32.dll")]<br />
public static extern int RegOpenKeyEx(System.UInt32 hKey, String lpSubKey, System.UInt32 ulOptions, System.UInt32 samDesired, System.UInt32 phkResult);<br />
1) I'm not sure if I've setted types correctly
2) how I define in C# code variable for phkResult? If I define it as UInt32 I can't do as I do in C &phResult...
Thanks in advance,
Paolo
|
|
|
|
|
Try the following:
[DllImport("advapi32.dll", CharSet=CharSet.Unicode, EntryPoint="RegOpenKeyEx")]
static extern long RegOpenKeyEx(
IntPtr hKey,
String subKey,
uint options,
int sam,
out IntPtr phkResult);
- Nick Parker My Blog | My Articles
|
|
|
|
|
.NET already implements the registry API's.
Check the Microsoft.Win32.Registry class.
|
|
|
|
|
thanks you opened my eyes =), I was just playing around with that class but a new problem came at my hands...... if I want to use a recorsive function to process keys how I do that?? In Win32 API, I've RegEnumerateKey/Values here the most similar thing is String [] subkey = rk.GetSubKeyNames(); , so I do
<br />
private void AddRegNode(TreeNode node, RegistryKey root)<br />
{<br />
RegistryKey rk = root; <br />
String [] subkey = rk.GetSubKeyNames();<br />
if(subkey.Length==0) return;
foreach (String s in subkey)<br />
{<br />
String livia = rk.Name + "\\" + s;<br />
RegistryKey temp = Registry.CurrentUser.CreateSubKey(livia);<br />
TreeNode newNode = new TreeNode(s);<br />
this.Tree.SelectedNode.Nodes.Add(newNode);<br />
AddRegNode(newNode, temp);<br />
but doing so it doesn't work, first all the nodes are added to selected node, but I'l fix it, second it desn't go deeper ( HKEY_CURRENT_USER\AppEvents\EventLabels is max deep it reaches)
thanks
Paolo
|
|
|
|
|
I wrote a simple window application that fills a treeview with registry keys.
The code fills the tree with the registry keys (no values)
private void FillNode(TreeView treeView, TreeNode parentNode, RegistryKey key)
{
int index = key.Name.LastIndexOf("\\");
string keyname = key.Name;
if (index > 0)
{
keyname = key.Name.Remove(0, index + 1);
}
TreeNode node = null;
if (null == parentNode)
{
node = treeView.Nodes.Add(keyname);
}
else
{
node = parentNode.Nodes.Add(keyname);
}
string[] subkeyNames = key.GetSubKeyNames();
RegistryKey subkey = null;
foreach (string subkeyName in subkeyNames)
{
try
{
subkey = key.OpenSubKey(subkeyName);
}
catch (SecurityException e)
{
continue;
}
FillNode(treeView, node, subkey);
subkey.Close();
}
}
To use it call:
FillNode(treeView1, null, Microsoft.Win32.Registry.CurrentUser);
Where treeView1 is your TreeView control.
Notes:
1. If you read the keys them use OpenSubKey and not CreateSubKey
2. Make sure you catch exception. There are keys you cannot open.
3. Don't forget to close keys that you open.
Good luck,
Ami
|
|
|
|
|
Hello,
I have a datagrid with a list of customers. I want to be able to click on the row then be able to display the customer number which is in the first column of that row.
I have code for finding the row number:
rowNumber = grdDisplayCustomers.CurrentRowIndex;
But how do find out the customer number which is in the first column of that row.
Many thanks in advance,
Steve
|
|
|
|
|
You use either the DataView you might have assigned to the DataGrid , or get the CurrencyManager and query for the DataRow with that index. Don't simply use the DataSet or DataTable because after sorting the DataGrid those rows our out of sync. An example follows:
CurrencyManager cm = (CurrencyManager)dataGrid1.BindingContext[
dataGrid1.DataSource, dataGrid1.DataMember];
if (cm != null)
{
DataView view = cm.List as DataView;
if (view != null)
{
DataRowView rowView = view[rowIndex];
object value = rowView[0];
if (value != null) return value.ToString();
else return null;
}
} An IndexOutOfRangeException may be thrown in this sample at view[rowIndex] , but that should actually be a desired effect from this code (make sure you handle it, though).
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles] [My Blog]
|
|
|
|