|
Hey,
Firstly I'm using VS 2005 Beta2.
I'm using databinding to a combobox which is populated with user defined objects (of the same type), and the databinding is on the it's SelectedItem property.
<br />
Binding bOnX = new Binding("SelectedItem", myDataSource, "objX");<br />
<br />
bOnX.DataSourceUpdateMode = DataSourceUpdateMode.OnPropertyChanged;<br />
<br />
comboBox.DataBindings.Add(bOnX);<br />
Now I know by default the databinding is onValidation hence I've changed it to OnPropertyChanged. However, it still does not bind to the data source when I changed the selected item, only when I move focus to another control. With that said, I'm also using the same DataSourceUpdateMode for a text box with a databinding on it's Text property and that works every time the text changes in the TextBox.
I think (please correct me if I'm wrong) that the OnPropertyChanged on works on the the property being bound to, for eg.:
for,
Binding bOnX = new Binding("Text", myDataSource, "strX");
DataSourceUpdateMode.OnPropertyChanged, works on the TextChanged event
but because there is no SelectedItemChanged event it does not work on the former example.
Can anyone please let me know if I'm right or wrong, and either way, please suggest a solution.
chukkykzn
chukkykzn@msn.com
|
|
|
|
|
Hi,
I'm looking for a way to change the default height of the propertygrid description pane.
The only property we have from the Propertygrid object is HelpVisible, but not any which could set its height.
I looked inside the object, and the PropertyGridInternal.DocComment object is the description pane object, but it is private and its impossible to access to its properties (like Height...).
I also tried to derive the propertygrid object and access to its child controls, but it does not change anything :
class MyPropertyGrid : System.Windows.Forms.PropertyGrid
{
public MyPropertyGrid
{
}
public void ChangeHeight()
{
foreach(Control ctl in this.Controls)
{
if(ctl.Text == "Description Pane")
ctl.Height = 100;
}
}
}
It might possible, because the PropertyGrid of the object properties in Visual Studio does remember the height of the description pane (try to change it, close VS, reopen it and see!).
Thanks in advance,
Touffic
|
|
|
|
|
hi,
Our marketing team wants to release a product that should run only run on the computer of the user for an X amount of days, after that it should just show some messagebox. Kind of like a time trial version.
Now my question is, how can I make this as tamper proof as possible, since people can still put their windows clock 1 year back, and keep working with the program.
Any hints and/or tips where I should look at?
thanks,
Gidon
|
|
|
|
|
Hi...
just a small suggestion... maybe you can build your application to do a date check upon every execution... as long as there is a difference between this captured date and the saved date... increase your counter by the difference (x) ... take it as the application has been running for x numbers of days... then save this new date... thus even if i were to set the date back 1 week... the program will acknowledge this as the program being used for 1 week...
thus when the counter reaches, say 30... the trial period will end... make sure to encrypt the counter value...
there is a way to tamper though... that would be for the user to set the date to the same as the first launch date everytime before starting the program... or they found a way to tamper with your counter value...
just a suggestion...
|
|
|
|
|
Hello friends!
I'm in the process of conceptualizing a test program that (hopefully) shuts down my unit for a given time but the catch is I want the program to close all running applications first particularly my internet connection (since i'm using dial-up connection) and shuts down my unit properly. Is this do-able in c# and if so could someone please give me a boost on this.
I'm fairly new to programming let alone c# and i'm trying to scroll through the namespaces and i can't seem to get a solution for my problem. So any assistance regarding this matter would mean gold to me. Thanx for all your helps!
Oh yeah I'm using Windows XP home ed and VS.NET 2003. Almost forgot..
Kampai!!!
|
|
|
|
|
you can try using kill() to kill the processes
you can try searching msdn for "C# kill process"
|
|
|
|
|
Hey thanx!
I found a similar program that shuts down a machine for a give time but the problem is it forces applications to terminate meaning it doesn't close applications properly. Any lead on this? How can i access my tool bar using c#? Thanx!
Kampai!!!
|
|
|
|
|
maybe you can use
myProcess.CloseMainWindow();
but this only works with application with user interface. It behaves the same as selectign close from the application interface. There will be a user prompt for any unsaved data.
but for applications without user interface, you will need to use
myProcess.Kill()
hope this helps
|
|
|
|
|
Indeed!
Thanx for the assistace it was such a big help! I gues i've no choice but to force terminate every application and hopefully doesn't ruin my machine . Thanx again frend!
Kampai!!!
|
|
|
|
|
my idea is to save the files in a tempory folder other than the existing folder when the system is shut down.
how to do it.
|
|
|
|
|
Directory.CreateDirectory[^]
File.Copy[^]
Insert following into your main form to detect system shut down.
protected override void WndProc(ref Message m)
{
if (m.Msg == 0x0011)
{
}
base.WndProc(ref m);
}
www.troschuetz.de
-- modified at 3:40 Tuesday 30th August, 2005
|
|
|
|
|
Whether we can able to save all the open files automatically before the system shutdown.Also there exist any APIs for saving filet in c sharp.net.
I am expecting your most valuable reply
|
|
|
|
|
What do you mean by "all the open files"? What types of files do you open where and how?
www.troschuetz.de
|
|
|
|
|
I'm looking for way to capture audio (from microphone) and video (from webcam) and stream across network.. but most of examples that i have found are for web page web cam apps and thats not what i'm looking for. I came across one app example to capture webcam images but can't 'refind' the link.. and microphone capture eludes me.. I've been working on various aspects of this project for days now and could have easly passed them over by sheer exhaustion (coding can be an obsession).. any tips or pointers on simple audio/video device capture using p/invoke would forever indebted... Thank you for your time in reading my plea for help
When this darn code gets finished.. look for my article
|
|
|
|
|
Try this article:
http://www.codeproject.com/cs/media/directxcapture.asp
It is about Audio-Video capture in DirectX, and it is awesome!
[ITA] Tozzi ha ragione: Gaia si sta liberando di noi.
[ENG] Tozzi is right: Gaia is obliterating us.
|
|
|
|
|
How can I write superscript in label in winform. I need write l.s-1. How can I do this?
Thanks
My skills:
HTML - advance
PHP - advance
MySQL - advance
Perl and Embperl - beginner
C# - beginner
PostgreSQL - beginner
3D Studio - beginner
AutoCAD - profesional
Patrik Ružič
|
|
|
|
|
I don't believe you can, unless you owner draw. A label just uses one font, and fonts do not have the ability to superscript. You can put the number on the end in a smaller font, in a new label, or owner draw ( that is, write your own label class )
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace shutdown
{
///
/// Summary description for Form1.
///
public class frmshutdown : System.Windows.Forms.Form
{
internal System.Windows.Forms.GroupBox grpQuestion;
internal System.Windows.Forms.Button btnDo;
internal System.Windows.Forms.RadioButton rdbLock;
internal System.Windows.Forms.RadioButton rdbLogoff;
internal System.Windows.Forms.RadioButton rdbRestart;
internal System.Windows.Forms.RadioButton rdbShutdown;
///
/// Required designer variable.
///
private System.ComponentModel.Container components = null;
public frmshutdown()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
///
/// Clean up any resources being used.
///
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
///
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
///
private void InitializeComponent()
{
this.grpQuestion = new System.Windows.Forms.GroupBox();
this.btnDo = new System.Windows.Forms.Button();
this.rdbLock = new System.Windows.Forms.RadioButton();
this.rdbLogoff = new System.Windows.Forms.RadioButton();
this.rdbRestart = new System.Windows.Forms.RadioButton();
this.rdbShutdown = new System.Windows.Forms.RadioButton();
this.grpQuestion.SuspendLayout();
this.SuspendLayout();
//
// grpQuestion
//
this.grpQuestion.Controls.Add(this.btnDo);
this.grpQuestion.Controls.Add(this.rdbLock);
this.grpQuestion.Controls.Add(this.rdbLogoff);
this.grpQuestion.Controls.Add(this.rdbRestart);
this.grpQuestion.Controls.Add(this.rdbShutdown);
this.grpQuestion.Location = new System.Drawing.Point(26, 56);
this.grpQuestion.Name = "grpQuestion";
this.grpQuestion.Size = new System.Drawing.Size(240, 160);
this.grpQuestion.TabIndex = 1;
this.grpQuestion.TabStop = false;
this.grpQuestion.Text = "What do you want to do?";
//
// btnDo
//
this.btnDo.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnDo.Location = new System.Drawing.Point(160, 120);
this.btnDo.Name = "btnDo";
this.btnDo.Size = new System.Drawing.Size(64, 23);
this.btnDo.TabIndex = 5;
this.btnDo.Text = "Do";
this.btnDo.Click += new System.EventHandler(this.btnDo_Click);
//
// rdbLock
//
this.rdbLock.Location = new System.Drawing.Point(16, 120);
this.rdbLock.Name = "rdbLock";
this.rdbLock.Size = new System.Drawing.Size(128, 24);
this.rdbLock.TabIndex = 4;
this.rdbLock.Text = "Lock Computer";
//
// rdbLogoff
//
this.rdbLogoff.Location = new System.Drawing.Point(16, 88);
this.rdbLogoff.Name = "rdbLogoff";
this.rdbLogoff.Size = new System.Drawing.Size(128, 24);
this.rdbLogoff.TabIndex = 3;
this.rdbLogoff.Text = "Log off";
//
// rdbRestart
//
this.rdbRestart.Location = new System.Drawing.Point(16, 56);
this.rdbRestart.Name = "rdbRestart";
this.rdbRestart.Size = new System.Drawing.Size(128, 24);
this.rdbRestart.TabIndex = 2;
this.rdbRestart.Text = "Restart";
//
// rdbShutdown
//
this.rdbShutdown.Checked = true;
this.rdbShutdown.Location = new System.Drawing.Point(16, 24);
this.rdbShutdown.Name = "rdbShutdown";
this.rdbShutdown.Size = new System.Drawing.Size(128, 24);
this.rdbShutdown.TabIndex = 1;
this.rdbShutdown.TabStop = true;
this.rdbShutdown.Text = "Shutdown";
//
// frmshutdown
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.grpQuestion);
this.Name = "frmshutdown";
this.Text = "shutdown";
this.Load += new System.EventHandler(this.frmshutdown_Load);
this.grpQuestion.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
///
/// The main entry point for the application.
///
[STAThread]
static void Main()
{
Application.Run(new frmshutdown());
}
private void btnDo_Click(object sender, System.EventArgs e)
{
shutmode st=new shutmode();
if(rdbShutdown.Checked == true)
st.Shutdown(); //for shutdown
else if(rdbRestart.Checked == true)
st.Restart(); // Restart
else if(rdbLogoff.Checked == true)
st.LogOff(); //' Log off
else if(rdbLock.Checked ==true)
st.LockTheComputer();//' Lock Workstation
else
MessageBox.Show("Invalid option", "Illegal operation", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
// ' Invalid Radio Button (should never been shown)
}
}
}
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.IO;
namespace shutdown
{
///
/// Summary description for shutmode.
///
public class shutmode
{
public shutmode()
{
//
// TODO: Add constructor logic here
//
}
// Constants
const int SE_PRIVILEGE_ENABLED=2;
const int TOKEN_QUERY=8;
const int TOKEN_ADJUST_PRIVILEGES=32;
const string SE_SHUTDOWN_NAME= "SeShutdownPrivilege";
//' Exit Windows Constant
const int EWX_LOGOFF = 0;
const int EWX_SHUTDOWN= 1;
const int EWX_REBOOT = 2;
const int EWX_FORCE = 4;
const int EWX_POWEROFF = 8;
const int EWX_FORCEIFHUNG= 16;
[StructLayout(LayoutKind.Sequential, Pack=1)]
//'Structure
internal struct Luid
{
public int Count;
public long luid;
public int Attr;
};
//End Structure 'TokPriv1Luid
//' Lock Workstation
[DllImport("user32.dll", ExactSpelling=true)]
static extern bool LockWorkStation();
//' Get Current Processes
[DllImport("kernel32.dll", ExactSpelling=true)]
static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", SetLastError=true)]
static extern bool OpenProcessToken(IntPtr h, int acc,IntPtr phtok);
//' Look up Priviledge Value
[DllImport("advapi32.dll", SetLastError=true)]
internal static extern bool LookupPrivilegeValue(string host, string name,ref long luid) ;
// Adjust Token Priviledges
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, Luid newst, int len, IntPtr prev, IntPtr relen) ;
//' Exit Windows
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true)]
internal static extern bool ExitWindowsEx(int flg, int rea) ;
//' Exit Windows Sub
private void DoExitWindows(int flg)
{
Luid tp;
bool s;
int h1,h2;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
OpenProcessToken(hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, htok);
tp.Count = 1;
tp.luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
LookupPrivilegeValue(null, SE_SHUTDOWN_NAME,ref tp.luid);
AdjustTokenPrivileges(htok, false, tp, 0, IntPtr.Zero, IntPtr.Zero);
ExitWindowsEx(flg,0);
}
//' Shutdown
public void Shutdown()
{
DoExitWindows(EWX_SHUTDOWN);
}
// ' Restart
public void Restart()
{
DoExitWindows(EWX_REBOOT | EWX_FORCE);
}
//' Log off
public void LogOff()
{
DoExitWindows(EWX_LOGOFF);
}
//' Lock Workstation
public void LockTheComputer()
{
LockWorkStation();
}
}
}
-- modified at 1:46 Tuesday 30th August, 2005
|
|
|
|
|
It would help if instead of posting a million lines of code without comment, you told us what's wrong with it. Does it compile ? Does it do what you expect ? What do you expect ?
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
This program is for shutdown,logoff,restart the system.
the pgm is compile without any error.
The problem is when we call the function ,for example shutdown ,the control is going to the ExitWindows()function.But its returned value is "0";so the shutdown command fails.i am unable to detect why the returned value is 0.
|
|
|
|
|
OK, that's a lot more helpful
So long as we're copying and pasting code, here's the code I found online to do this when I had the same problem as you. I think in a nutshell, some sort of privilege thing needs to happen first, which gives your app the *right* to shut down the PC.
public class Shutdown
{
[StructLayout(LayoutKind.Sequential, Pack=1)]
internal struct TokPriv1Luid
{
public int Count;
public long Luid;
public int Attr;
}
[DllImport("kernel32.dll", ExactSpelling=true) ]
internal static extern IntPtr GetCurrentProcess();
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool OpenProcessToken( IntPtr h, int acc, ref IntPtr phtok );
[DllImport("advapi32.dll", SetLastError=true) ]
internal static extern bool LookupPrivilegeValue( string host, string name, ref long pluid );
[DllImport("advapi32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool AdjustTokenPrivileges( IntPtr htok, bool disall,
ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen );
[DllImport("user32.dll", ExactSpelling=true, SetLastError=true) ]
internal static extern bool ExitWindowsEx( int flg, int rea );
internal const int SE_PRIVILEGE_ENABLED = 0x00000002;
internal const int TOKEN_QUERY = 0x00000008;
internal const int TOKEN_ADJUST_PRIVILEGES = 0x00000020;
internal const string SE_SHUTDOWN_NAME = "SeShutdownPrivilege";
internal const int EWX_LOGOFF = 0x00000000;
internal const int EWX_SHUTDOWN = 0x00000001;
internal const int EWX_REBOOT = 0x00000002;
internal const int EWX_FORCE = 0x00000004;
internal const int EWX_POWEROFF = 0x00000008;
internal const int EWX_FORCEIFHUNG = 0x00000010;
private static void DoExitWin( int flg )
{
bool ok;
TokPriv1Luid tp;
IntPtr hproc = GetCurrentProcess();
IntPtr htok = IntPtr.Zero;
ok = OpenProcessToken( hproc, TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, ref htok );
tp.Count = 1;
tp.Luid = 0;
tp.Attr = SE_PRIVILEGE_ENABLED;
ok = LookupPrivilegeValue( null, SE_SHUTDOWN_NAME, ref tp.Luid );
ok = AdjustTokenPrivileges( htok, false, ref tp, 0, IntPtr.Zero, IntPtr.Zero );
ok = ExitWindowsEx( flg, 0 );
}
public static void ShutDown()
{
DoExitWin( EWX_POWEROFF | EWX_FORCE );
}
}
}
Christian Graus - Microsoft MVP - C++
-- modified at 2:02 Tuesday 30th August, 2005
|
|
|
|
|
First Thanks for helping me.
I am a new programmer.So i want to know what happend inside my program(means why i am getting the return value 0 from the Exitwindows()).Expecting the reason for that thing
|
|
|
|
|
I am using the FileStream class to write and read from files. I am using it in a server to which the clients can connect and read data from the file(s). The server, on the other hand is also writing data to the files after regular intervals of time. To write the data to the file, the server creates a FileStream object in the following way:
FileStream dataStream = new FileStream(dataFileName, FileMode.Open, FileAccess.Write);
As is clear from above, the server opens the file in write only mode and it shouldn't be a problem to read from the file.
To read data from the file, following code is used:
FileStream stream = new FileStream(fileNames[i].ToString(), FileMode.Open, FileAccess.Read);
As is clear here, I open the file in read-only mode. The problem is, that if the above code executes during the time when the server has already opened the stream for writing, I get an exception (Cannot access the file as it is being used by some other process).
Any help in this regard would be highly appreciated
|
|
|
|
|
No matter how logical it seems to you, Windows will not allow it, one process needs to release the file before another can access it. In the lack of deterministic destruction, that means the using keyword, or an explicit call to Close().
Christian Graus - Microsoft MVP - C++
|
|
|
|
|
Thanks a lot Graus for your response, but still, is there any way out of this problem?
|
|
|
|
|