|
on a simple window form, there is a small panel, along with button and groupbox inside the panel.
When I change the main window form color (i.e. this.BackColor = Color.Red) and the main form does turn red, and also the panel and groupbox were also changed to red. HUH?
I just wanted the main form background color to be red, while the inside of the panel (and the panel itself) to remain unchanged.
How do I do that? I tried goggling and turns out no luck.
HELP!
|
|
|
|
|
because the backcolor properties for the panel and groupbox were not initialised.
If you set their backcolors first then change the forms backcolor they will not change.
|
|
|
|
|
hmm interesting... thanks and tried it and does work.
I have not realized this.
Thanks a heap!
|
|
|
|
|
FYI The BackColor property, along with several others, is what is called an Ambient Property. This means that it gets its value from its parent control if it has not been changed first.
Have a Google for ambient properties c# to get more details.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Well if you want that I can give you little source code wish that help you : I give this code here in vb 2005 it's almost same in c# . dont know where you want to use visual basic or c#
Private Sub lblbgcl_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lblbgcl.Click
Dim mybackcolor As New ColorDialog()
If mybackcolor.ShowDialog() = Windows.Forms.DialogResult.OK Then
Me.BackColor = mybackcolor.Color
Me.MenuStrip1.BackColor = nothing
'' Write here what you want
Me.Groupbox1.backcolor=nothing
End If
End Sub
|
|
|
|
|
|
Don't post the same question in multiple forums. It's considered rude and will not get you an answer any faster.
|
|
|
|
|
I cannot find much on this.. but I am looking to get the Department and Company field from active directory... here is what I have:
PrincipalContext adPrincipalContext = new PrincipalContext(ContextType.Domain, "********");
UserPrincipal findUser = UserPrincipal.FindByIdentity(adPrincipalContext, Name);
return findUser.EmailAddress;
Now I can get the email address just fine.. but I do not see anything for UserPRincipal in getting the Department and Company fields?
|
|
|
|
|
Hello;
I'm building an application in winforms c# 3.0. I want to disable the mouses's right button click when the application is running on all the system (in order to prevent copy/paste).
I succeeded in blocking the keyboard keys but not the mouse button. Can you figure out why the code for the mouse does not work?
The problem comes from LowLevelMouseProc()
Thanks for help.
#region
using System;
using System.ComponentModel;
using System.Drawing;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
#endregion
namespace GlobalHook
{
public class UserActivityHook
{
private const int VmRButton = 0x02;
private const int VkLControl = 0xA2;
private const int VkRControl = 0xA3;
private const int VkControl = 0x11;
private const int VkSnapshot = 0x2C;
private const int WhKeyboardLl = 13;
private const int WhMouseLl = 14;
private const int WmKeydown = 0x0100;
private const int WmMousedown =0x0201;
private static IntPtr kbh_Handle;
private static IntPtr kbh_Handle1;
private static HookProc KeyboardHookProcedure;
private static HookProc MouseHookProcedure;
private int HMouseHook;
private int HKeyboardHook;
#region Windows Function Imports
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
private static extern int SetWindowsHookEx(int idHook, HookProc lpfn, IntPtr hMod, int dwThreadId);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
public static extern int CallNextHookEx(IntPtr hhk, int nCode, int wParam, IntPtr lParam);
[DllImport("user32.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.StdCall,
SetLastError = true)]
private static extern int UnhookWindowsHookEx(int idHook);
private delegate int HookProc(int nCode, int wParam, IntPtr lParam);
#endregion
#region Windows constants
#endregion
~UserActivityHook()
{
Stop(true, true, false);
}
public void Start()
{
if (HMouseHook == 0)
{
MouseHookProcedure = new HookProc(LowLevelMouseProc);
HMouseHook = SetWindowsHookEx(WhMouseLl, MouseHookProcedure, Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]), 0);
if (HMouseHook== 0)
{
int errorCode = Marshal.GetLastWin32Error();
Stop(true, false, false);
throw new Win32Exception(errorCode);
}
}
if (HKeyboardHook == 0)
{
KeyboardHookProcedure = new HookProc(LowLevelKeyboardProc);
HKeyboardHook = SetWindowsHookEx(WhKeyboardLl, KeyboardHookProcedure,
Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
0);
if (HKeyboardHook == 0)
{
int errorCode = Marshal.GetLastWin32Error();
Stop(false, true, false);
throw new Win32Exception(errorCode);
}
}
}
public void Stop()
{
Stop(true, true, true);
}
public void Stop(bool uninstallMouseHook, bool uninstallKeyboardHook, bool throwExceptions)
{
if (HMouseHook != 0 && uninstallMouseHook)
{
int retMouse = UnhookWindowsHookEx(HMouseHook);
HMouseHook = 0;
if (retMouse == 0 && throwExceptions)
{
int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode);
}
}
if (HKeyboardHook != 0 && uninstallKeyboardHook)
{
int retKeyboard = UnhookWindowsHookEx(HKeyboardHook);
HKeyboardHook = 0;
if (retKeyboard == 0 && throwExceptions)
{
int errorCode = Marshal.GetLastWin32Error();
throw new Win32Exception(errorCode);
}
}
}
private static int LowLevelKeyboardProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode < 0)
{
CallNextHookEx(kbh_Handle, nCode, wParam, lParam);
return 0;
}
if (wParam == WmKeydown)
{
IntPtr kbdll = lParam;
Kbdllhookstruct kbdllstruct = (Kbdllhookstruct) Marshal.PtrToStructure(kbdll, typeof (Kbdllhookstruct));
if ((kbdllstruct.VkCode == VkSnapshot) || (kbdllstruct.VkCode == VkControl) || (kbdllstruct.VkCode == VkLControl) || (kbdllstruct.VkCode == VkRControl))
return -1;
}
return CallNextHookEx(kbh_Handle, nCode, wParam, lParam);
}
private static int LowLevelMouseProc(int nCode, int wParam, IntPtr lParam)
{
if (nCode < 0)
{
CallNextHookEx(kbh_Handle1, nCode, wParam, lParam);
return 0;
}
if (wParam == WmMousedown)
{
IntPtr msdll = lParam;
MouseLlHookStruct msdllstruct = (MouseLlHookStruct)Marshal.PtrToStructure(msdll, typeof(MouseLlHookStruct));
if (msdllstruct.MouseData == VmRButton)
return -1;
}
return CallNextHookEx(kbh_Handle1, nCode, wParam, lParam);
}
[StructLayout(LayoutKind.Sequential)]
private struct Point
{
public int X;
public int Y;
}
[StructLayout(LayoutKind.Sequential)]
private struct MouseLlHookStruct
{
public Point Point;
public int MouseData;
public int Flags;
public int Time;
public int ExtraInfo;
}
#region Nested type: Kbdllhookstruct
[StructLayout(LayoutKind.Sequential)]
public struct Kbdllhookstruct
{
public int VkCode;
public int ScanCode;
public int Flags;
public int Time;
public int ExtraInfo;
}
#endregion
}
}
|
|
|
|
|
teycir wrote: (in order to prevent copy/paste).
This is a lot of work just to find out your premise is flawed. You are not going to prevent all possible Copy'N'Paste possibilities just by hooking the mouse and eating the right button clicks. Besides, applications use the right button for other things other than Copy'N'Paste.
|
|
|
|
|
teycir wrote: in order to prevent copy/paste
So you're writing a piece of malware and asking for help.
Is there a good reason to prevent copy/paste? I don't think so.
Disabling the right mouse button is not going to help though.
|
|
|
|
|
Why are you trying to disable copy/paste systemwide? I can't think of a single legit reason to do so. If your requirement is to keep the user from copying data out of your application, your focus should be on changing the behavior of your application only; not affecting the entire system.
It is a truth universally acknowledged that a zombie in possession of brains must be in want of more brains.
-- Pride and Prejudice and Zombies
|
|
|
|
|
Others are right, forget this line of reasoning. As an example of another approach - you can monitor the clipboard and whenever something appears, just erase it. This will effectively disable copy/paste in the entire system. But why you need to do that is beyond me. If it's giving you thrills to write some kind of stupid malware, just do us a favor and get yourself a gf.
|
|
|
|
|
The software I'm working on is a demand of a client to prevent the theft of data from his employees when they use a software. I'm not building this for myself.
If you have no idea on how to proceed to solve the problem, please don't post your dumb comments.
|
|
|
|
|
In my defense - the idea of monitoring and erasing the clipboard wasn't that dumb, better that your hooking the mouse. Don't forget to disable the print screen as well, when you are at it.
|
|
|
|
|
Printscreen and ctrl l ctrl r ctrl keys are disabled. U should have noticed that, I mentionned it in the post and it's easy to see in u read and understood a little bit the code.
|
|
|
|
|
So in the end it's me who can't code. Do you really think anybody would read your several pages long code if it's supposed to be such a lame way of data protection?
|
|
|
|
|
Yes u r unable to understand a single simple class and u r more a pain than a help with this post.
|
|
|
|
|
Damn me. It's funny that I was the only one who actually suggested a solution, yet I am the one most incompetent. Unlike you, Mr. Hook'em all. Well, good luck tilting at windmills, let's just hope that when you finally manage to disable all the system functions, your client's data will be safe.
PS: Don't forget to make the whole screen black all the time your app is on, some smartass might make a picture of it with his cell phone.
|
|
|
|
|
OK fixed the problem: removal of the struct for the mouse and replacement of the constant for themouse from 513 to 516
|
|
|
|
|
I completed the first step in my project, and with help from a few great people on this forum, I managed to get my edge detection algorithm to work adequately. Now on to my next goal. I have the edge detected video feed and can access all of its properties. What do you guys think is the best approach for judging the distance of a line on an image from the camera (robot). Lets say I can obtain the variables like angle of lens, angle of view, etc. What can I do with them in order to obtain distance data? Hough transformation works only for straight lines, so I am not sure how to approach this dilemma.
|
|
|
|
|
|
Thanks a bunch, btw what i meant by "only works on straight lines" was that i would encounter curved lines so it might not work well, but that you for the link, its going to help tremendously.
|
|
|
|
|
you're welcome.
|
|
|
|
|
Hi all,
I've wasted a day just trying to get a simple pointer back to C# from C++!
I have a C++ DLL returning an int* to a C# program. The problem is the int* in C# remains null after the assignment.
When I assign the C++ result to an IntPtr, I get a correct non-null value. However any attempt to assign this to an int* instantly results in null.
I've tried (from C#):
IntPtr intp = cppFunction ();
int* pi = (int *) intp;
int* pi = (int *) intp.ToPointer ();
void* vp = intp.ToPointer ();
int* pi = (int *) vp;
I then gave up on simple assignment, and tried to get the value by reference:
C#:
[DllImport("vdrdll.dll", EntryPoint = @"?getLineContentsAsArg@@YAXAAPAH@Z")]
public unsafe static extern void getLineContentsAsArg (ref int* lca);
C++:
DLLEXPORT void getLineContentsAsArg (int*& lca)
{
lca = calculateLineContents ();
}
A non-null pointer value is assigned in the DLL, but when it gets back to C#, it's null.
Can anyone tell me how to get an int* back to C#?
Thanks!
Alan
|
|
|
|