|
jspoonermso wrote: Is it possible to somehow make a c# winform invisible.
Yep, i'd set the Visible property to false
private void FormName_Load(object sender, EventArgs e)
{
this.Visible = false;
}
|
|
|
|
|
Just dropping a form in a service, visible or no, doesn't give the serivce a message pump.
|
|
|
|
|
Hi Dave,
I don't mean to butt in here, but.... The OP is not exactly clear, however the way I understood it was he's got a 3rd party thing that works in a WinForm. He'd like to use it in a service but it doesn't work for reasons unknown to us. He'd settle for using it in a form but would like to hide it and "pretend" it's a service. Of course he can't start, stop, or communicate with it like it is a service but beggars can't be choosers.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
Yes thats correct, my quyestion wasn't clear. My third party component seems only to work in forms and its just my guess that it wants a message pump, because there is an api function with the word 'advise' in it.
I did try setting my visibility to 'False'. If it were c++ there was something like ShowWindow(SW_HIDE) that would do the trick.
|
|
|
|
|
Again, you're guessing. Your best source of information is the people who wrote the library.
|
|
|
|
|
Sorry for my inadequate guessing but i don't have that recourse.
So I have found a way to make my program work in my own inferior wild guessing method.
I have a program that has a message pump is invisible and seems to do the job. My original question was about making the form invisible since setting the visible property didnt work. all figured out now.
|
|
|
|
|
Yeah I know, I didn't bother replying to that portion of the question simply because you're suggestion of contacting the vendor / developer is the best bet, I was just trying to tell him the form has a visibility property which was the first half of his question.
|
|
|
|
|
You would think. I tried that and my form still popped up.
|
|
|
|
|
Don't you hate when that happens?
Here are some other things to try. You can do these in the Properties window of Visual Studio:
<br />
this.ShowInTaskbar = false;<br />
this.WindowState = System.Windows.Forms.FormWindowState.Minimized;<br />
And/or this in load event handler:
this.Hide();
Hope that helps.
BDF
People don't mind being mean; but they never want to be ridiculous.
-- Moliere
|
|
|
|
|
I found a means to do it on the web. The 'Visible' property stubbornly did not work for me. But I was able to use the win32 ShowWindow Function. Code below.
And yes, you guys are correct its better to have a windows service, and it would be better if my third party dll would work without a message pump but its a legacy application. My guess is it uses netdde which is windows message based.
So the fix was to :
using System.Diagnostics;
using System.Runtime.InteropServices;
Then get access to the Win32 ShowWindow API call:
private const int SW_HIDE = 0;
[DllImport("User32")]
private static extern int ShowWindow(int hwnd, int nCmdShow);
Then when the form loads call a function that goes out, finds the app and hides it.
foreach (Process pr in processRunning)
{
try
{
if ((pr.MainWindowTitle == "mywindowname")||pr.ProcessName.Contains("mywindow.exe"))
{
hWnd = pr.MainWindowHandle.ToInt32();
ShowWindow(hWnd, SW_HIDE);
}
}
catch (Exception)
{
}
}
|
|
|
|
|
Your idea brought my mind another idea about my another project . Thank you.
By the way you can use this code to hide your Form.
private void Form1_Load(object sender, EventArgs e)
{
this.Opacity = 0.0f;
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
}
|
|
|
|
|
Hello friends,
I have written this small piece of code to detect autorun.inf files, particularly in the C: and the D: drive:-
<br />
using System;<br />
using System.IO;<br />
class search<br />
{<br />
public static void Main()<br />
{<br />
Console.WriteLine("Autorun checker");<br />
if (File.Exists("C:/autorun.inf") || File.Exists("D:/autorun.inf"))<br />
{<br />
Console.WriteLine("Autorun Detected. Press Enter to delete it.");<br />
Console.ReadLine();<br />
File.Delete("C:/autorun.inf");<br />
File.Delete("D:/autorun.inf");<br />
Console.WriteLine("Autorun Deleted successfully.");<br />
Console.ReadLine();<br />
}<br />
else<br />
{<br />
Console.WriteLine("No Autorun Detected. Press Enter to exit.");<br />
Console.ReadLine();<br />
}<br />
}<br />
}<br />
Now, if no autorun files are detected in C:/ or D:/ drive, the program exits displaying "No Autorun Detected. Press Enter to Exit." But if detected, it successfully deletes that autorun file but throws a runtime exception. Suppose, it has detected an autorun.inf file in the C:/ drive, it will delete that file but throw some kind of exception like this:
File.Delete("D:/autorun.inf");
<br />
IOException was unhandled. The device is not ready
Can anyone help me out! I am new to .NET programming and dont posses that much knowledge about Exception handling.
Hope to hear from you guys soon,
Rajdeep.NET
|
|
|
|
|
This may be a silly question, but is your D: drive by any chance a CD or DVD drive? If so, then deleting files may not be too easy...
Oh, and PLEASE, use the code block button - it makes things easier to read.
If what you are trying to do is handle the error cleanly:
using System;
using System.IO;
class search
{
public static void Main()
{
Console.WriteLine("Autorun checker");
if (File.Exists(@"C:\autorun.inf") || File.Exists(@"D:\autorun.inf"))
{
Console.WriteLine("Autorun Detected. Press Enter to delete it.");
Console.ReadLine();
try
{
File.Delete(@"C:\autorun.inf");
}
catch (IOException ex)
{
Console.WriteLine("Unable to delete C:\\autorun.inf:\n{0}", ex);
}
try
{
File.Delete(@"D:\autorun.inf");
}
catch (IOException ex)
{
Console.WriteLine("Unable to delete D:\\autorun.inf:\n{0}", ex);
}
Console.WriteLine("Autorun Deleted successfully.");
Console.ReadLine();
}
else
{
Console.WriteLine("No Autorun Detected. Press Enter to exit.");
Console.ReadLine();
}
}
}
No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced.
This message is made of fully recyclable Zeros and Ones
|
|
|
|
|
Hey Griff,
Thanks for correcting the code man. And yes, I remember to post the codes in the code block in my further posts.
Thanks once again,
Rajdeep.NET
|
|
|
|
|
Answer[^]
My failometer is detecting vast quantities of FAIL!
"Its SQL - hardly programming..." (Caslen)
|
|
|
|
|
Don't you think its about time you begged, borrowed or stole a C# Primer Book and worked through it?
You really should be fed up with posting such elementary mistakes, I know I am.
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.”
|
|
|
|
|
Hear hear.
|
|
|
|
|
Hello,
I am writing a small console application which will accept user age and name under the Public void Accept_Details() function. Now I want that, on the basis of the input provided by the user in the public void Display_Details() function, he be shown the desired output. Like this:
Console.WriteLine("Enter your choice. Type 'age' to view user age or 'name' to view user name);
Now, if the user enters 'age', he will be shown this:
Console.WriteLine("User Age is: {0}", age);
Similar will be the case, if the user enters 'name'. How to do that?
Please help me out,
sorry for my poor english,
Rajdeep.NET
|
|
|
|
|
Um . . . take a look at the last question you just posted. It shows you how to get input from the user and how to make an if statement to write different output to the console.
or did i misunderstand what you need help with?
|
|
|
|
|
Seriously?? How about an if statement checking what the user entered.
Pick up a book on C# for beginners and work through it.
|
|
|
|
|
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
|
|
|
|