1.
What base class do all Web Forms inherit from?
System.Web.UI.Page
2. What is the difference between
Debug.Write and Trace.Write? When should each be used?
The Debug.Write call won't be compiled when the
DEBUG symbol is not defined (when doing a release build). Trace.Write calls
will be compiled.
Debug.Write is for information you want only in
debug builds, Trace.Write is for when you want it in release build as well.
3. Difference between Anchor and
Dock Properties?
Dock Property- Gets or sets which edge of the
parent container a control is docked to. A control can be docked to one edge of
its parent container or can be docked
to all edges and fill the parent container. For example, if you set this
property to DockStyle.Left, the left edge of the control will be docked to the
left edge of its parent control. Additionally, the docked edge of the
control is resized to match that of its container control.
Anchor Property->Gets or
sets which edges of the control are anchored to the edges of its
container.
A control can be anchored to one or more edges of
its parent container. Anchoring a control to its parent ensures that the
anchored edges remain in the same position relative to the edges
of the parent container when the parent container is resized.
4. When would you use ErrorProvider
control?
ErrorProvider control is used in
Windows Forms application. It is like Validation Control for ASP.NET pages.
ErrorProvider control is used to provide validations in Windows forms and
display user friendly messages to the user if the validation fails.
E.g:
If we went to validate the
textBox1 should be empty, then we can validate as below
1). You need to place the
errorprovide control on the form
private void
textBox1_Validating(object sender, System.ComponentModel.CancelEventArgs e)
{
ValidateName();
}
private bool ValidateName()
{
bool bStatus = true;
if (textBox1.Text ==
"")
{
errorProvider1.SetError
(textBox1,"Please enter your Name");
bStatus = false;
}
else
{
errorProvider1.SetError (textBox1,"");
return bStatus;
}
}
it check the textBox1 is empty .
If it is empty, then a message Please enter your name is displayed.
5. Can you write a class without
specifying namespace? Which namespace does it belong to by default?
Yes, you can, then the class belongs to global
namespace which has no name. For commercial products, naturally,
you wouldn't want global namespace.
6. You are designing a GUI
application with a windows and several widgets on it. The user then resizes the
app window and sees a lot of grey space, while the widgets stay in place.
What's the problem?
One should use anchoring for correct resizing.
Otherwise the default property of a widget on a form is top-left, so it stays
at the same location when resized.
7. How can you save the desired
properties of Windows Forms application?
.config files in .NET are supported through the API
to allow storing and retrieving information. They are nothing more
than simple XML files, sort of like what .ini files were before for Win32
apps.
8. So how do you retrieve the
customized properties of a .NET application from XML .config file?
Initialize an instance of AppSettingsReader class.
Call the GetValue method of AppSettingsReader class, passing in the name
of the property and the type expected. Assign the result to the appropriate
variable.
9. Can you automate this
process?
In Visual Studio yes, use Dynamic Properties for
automatic .config creation, storage and retrieval.
10.
My progress bar freezes up and dialog window shows
blank, when an intensive background process takes over.
Yes, you should've multi-threaded
your GUI, with taskbar and main form being one thread, and the background
process being the other.
11.
What's the safest way to deploy a Windows Forms
app?
Web deployment: the user always
downloads the latest version of the code, the program runs within security sandbox, properly written app will not
require additional security privileges.
12.
Why is it not a good idea to insert code into
InitializeComponent method when
working with Visual Studio?
The designer will likely through
it away, most of the code inside InitializeComponent is auto-generated.
13.
What's the difference between
WindowsDefaultLocation and WindowsDefaultBounds?
WindowsDefaultLocation tells the form to start up
at a location selected by OS, but with internally specified size. WindowsDefaultBounds delegates both size
and starting position choices to the OS.
14.
What's the difference between Move and
LocationChanged? Resize and SizeChanged?
Both methods do the same, Move
and Resize are the names adopted from VB to ease migration to C#.
15.
How would you create a non-rectangular window,
let's say an ellipse?
Create a rectangular form, set the TransparencyKey
property to the same value as BackColor, which will effectively make the background of the form
transparent. Then set the FormBorderStyle to FormBorderStyle.None, which will
remove the contour and contents of the form.
16.
How do you create a separator in the Menu
Designer?
A hyphen '-' would do it. Also,
an ampersand '&\' would underline the next letter.
17.
How's anchoring different from docking?
Anchoring treats the component as having the
absolute size and adjusts its location relative to the parent form. Docking treats the component location as absolute
and disregards the component size. So if a status bar must always be at the bottom
no matter what, use docking. If a button should be on the top right, but change
its position with the form being resized, use anchoring.
18.
How do you trigger the Paint event in
System.Drawing?
Invalidate the current form, the
OS will take care of repainting. The Update method forces the repaint.
19.
With these events, why wouldn't Microsoft combine
Invalidate and Paint, so
that you wouldn't have to tell it to repaint, and then
to force it to repaint?
Painting is the slowest thing the
OS does, so usually telling it to repaint, but not forcing it allows for the process to take place in the background.
20.
How can you assign an RGB color to a
System.Drawing.Color object?
Call the static method FromArgb
of this class and pass it the RGB values.
21.
What class does Icon derive from?
Isn't it just a Bitmap with a wrapper name around
it? No, Icon lives in System.Drawing namespace. It's not a Bitmap by default, and is treated separately
by .NET. However, you can use ToBitmap method to get a valid Bitmap object
from a valid Icon object.
22.
Before in my VB app I would just load the icons
from DLL, How can I load the
icons provided by .NET dynamically?
By using
System.Drawing.SystemIcons class, for example System.Drawing.SystemIcons.Warning produces an Icon with a warning sign in it.
23.
When displaying fonts, what's the difference
between pixels, points and ems?
A pixel is the
lowest-resolution dot the computer monitor supports.
Its size depends on user's
settings and monitor size. A point is
always 1/72 of an inch.
An em is the
number of pixels that it takes to display the letter M.
24.
Write a simple Windows Forms MessageBox statement.
System.Windows.Forms.MessageBox.Show
("Hello,
Windows Forms");
25.
Can you write a class without specifying namespace?
Which namespace does it
belong to by default??
Yes, you can, then the class
belongs to global namespace which has no name. For commercial products, naturally, you wouldn’t want global namespace.
26. You are designing a GUI application
with a window and several widgets on it.
The user then resizes the app window
and sees a lot of grey space, while the
widgets stay in place.
What’s the problem?
One should use anchoring for correct
resizing. Otherwise the default property of a
widget on a form is top-left, so
it stays at the same location when resized.
27.
How can you save the desired
properties of Windows Forms application?
.config files in
.NET are supported through the API to allow storing and retrieving information.
They are nothing
more than simple XML files, sort of like what .ini files were
before for Win32
apps.
28. So how do you retrieve the
customized properties of a .NET application from
XML .config file?
Initialize an
instance of AppSettingsReader class. Call the GetValue method of AppSettingsReader class, passing in the name of the property and the type
expected. Assign the result to the appropriate variable.
29.
Can you automate this process?
In Visual Studio
yes, use Dynamic Properties for automatic .config creation,
storage and
retrieval.
30.
My progress bar freezes up and
dialog window shows blank, when an
intensive background process takes over.
Yes, you should’ve
multi-threaded your GUI, with taskbar and main form being one thread, and the background process being the other.
31. What’s the safest way to deploy a
Windows Forms app?
Web deployment: the
user always downloads the latest version of the code; the program runs within security sandbox, properly written app will not require
additional security privileges.
32.
Why is it not a good idea to
insert code into InitializeComponent method when
working with Visual Studio?
The designer will
likely throw it away; most of the code inside InitializeComponentis auto-generated.
33.
What’s the difference between
WindowsDefaultLocation and WindowsDefaultBounds?
WindowsDefaultLocation
tells the form to start up at a location selected by
OS, but with internally
specified size. WindowsDefaultBounds
delegates both
size and starting position choices to the OS.
34.
What’s the difference between
Move and LocationChanged? Resize and SizeChanged?
Both methods do the
same, Move and Resize are the names adopted from
VB to ease migration to C#.
35.
How would you create a
non-rectangular window, let’s say an ellipse?
Create a
rectangular form, set the TransparencyKey property to the same value as BackColor, which will effectively make the background of the
form transparent.Then set the
FormBorderStyle to FormBorderStyle.None,
which will remove the contour and
contents of the form.
36.
How do you create a separator
in the Menu Designer?
A hyphen ‘-’ would do
it. Also, an ampersand ‘&\’ would underline the next letter.
37.
How’s anchoring different from
docking?
Anchoring treats the
component as having the absolute size and adjusts its
location relative to the
parent form.
Docking treats the
component location as absolute and disregards the component size.
So if a
status bar must always be at the bottom no matter what, use docking.
If a button should be
on the top right, but change its position with the form
being resized, use
anchoring.
38.
How to give line break in windows application?
By using \r\n.
ex: This my \r\n windows
application.
39.
How can you display a default value in the text box
of an input box?
You can display a default value
in the text box of an input box by
using the DefaultResponse argument
of theInputBox() function.
40.
How will you pick a color from
the ColorDialog box?
To pick a color from the color
dialog box, you need to create an instance
of the ColorDialog box and
invoke to theShowDialog() method.
The code to display the color
dialog box and set the BackColor property of the
Label control
similar to the color selected in the color dialog box control is:
private
void button1_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() !=
DialogResult.Cancel)
{
label1.Text = "Here's my new color!";
l abel1.BackColor
= colorDialog1.Color;
}
41.
How can you get or set the time between Timer
ticks?
There is
an Interval property, which is responsible to get and set the time
in
milliseconds.
42.
How can you programmatically position the cursor on
a given line or on a character
in the RichTextBoxcontrol in C#?
The RichTextBox control
contains the Lines array property, which displays one item of
an array in a
separate line. Each line entry has a Length property,
which can be used to accurately
position the cursor at a character, as shown in the
following code snippet:
private
void GoToLineAndColumn(RichTextBox RTB, int Line, int Column)
{
int
offset = 0;
for(int
i = 0; i < Line -1 && i < RTB.Lines.Length; i++)
{
offset
+= RTB.Lines[i].Length + 1;
}
RTB.Focus();
RTB.Select(offset
+ Column, 0);
}
43. What is the difference between the WindowsDefaultLocation
and WindowsDefaultBounds properties?
The WindowsDefaultLocation property
makes the form to start up at a location selected by the operating system, but
with internally specified size. The WindowsDefaultBounds property
delegates both size and starting position choices to the operating system.
44.
Where does an ImageList control appear
when you add it at the design time?
The ImageList control
is a component; therefore, it appears in the component tray at the design time.
45.
How can you programmattically prevent a Combobox
from dropping, in .NET 4.0?
To avoid dropping of a Combobox,
you need to override the WndProc() method
and ignore WM_LBUTTONDOWN andWM_LBUTTONDBLCLK events.
46.
What is the function of the CheckState property
of the CheckBox control?
The CheckState property
gets or sets the state of CheckBox.
If
the ThreeState property is set to false,
the CheckState property value can
only be set
toCheckState.Indeterminate in code and not by user interaction.
Checked -
The CheckBox displays a check mark. The control appears sunken.
Unchecked - The CheckBox is
empty. The control appears raised.
Indeterminate -
The CheckBox displays a check mark and is shaded.
47.
Write a code to select an item in the ListView control
programmatically in C#?
To select an item from
the ListView control, you can use the following code snippet:
//Make
sure the listview has focus
Listview1.Focus();
listview1.Items[i].Selected
= true;
48.
Differentiate between a TextBox control
and RichTextBox control.
The TextBox control is
an input control, which allows a user to enter text to
an application at
runtime. By default, it allows only single line text; however,
you can change its property to accept the
multiline text as well as scroll bar also.
The RichTextBox control
is similar to the TextBox control with the difference that itallows the user to format its text also. You can format the text in various ways,
such as bold, italic, and underlined as well as change its color and font. You can
save your RichTextBox value to a RTF (Rich Text Format) file and load value of RTF
file to theRichTextBox control.
49.
Describe the ToolTip control. How can you
associate it with other controls?
The ToolTip control
generates a small pop-up window with explanatory text for an element It is
displayed when the user pauses the mouse for a certain
period over an element/control.
Tool tips provide a quick help to user to understand about that element. To
associate a tool tip with other control,
you need to implement
the SetToolTip()method.
50.
What does the DialogResult property of a Button control
do?
The DialogResult property
retrieves or sets a value that is returned to the parent
form when the button
is clicked.
No comments:
Post a Comment