|
abiemann wrote: a singleton was purely for good design
I agree with Luc. Singletons are rarely a good design.
|
|
|
|
|
I just need a quick answer to this question.
If I have a custom class that implements IDisposable, in my void Dispose(){}; function whats supposed to go in there? Do I null all the resources I am using?
Any help would be appreciated.
|
|
|
|
|
There are many good articles at codeproject about the IDisposable pattern. I strongly suggest you read them
|
|
|
|
|
|
Whatever you want; it doesn't need to do anything if there's nothing to do.
I tend to empty collections there.
|
|
|
|
|
i have xml file
iam having c# application
i need to
1-read xml file in c# abd pass it as parameter to sql server store procedure (parameter type xml)
2- use procedure have xml parameter to insert data into table
md_refay
|
|
|
|
|
And what have you tried so far?
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I think nothing... Just asked us before starting anything.. .
|
|
|
|
|
I think you need to read books on C# before you start. Reading and passing XML data to procedure is pretty easy. Just need basic knowledge on Database types and create XML.
For quick knowledge, you might consider Linq to XML. Its the easiest.
|
|
|
|
|
Hi there.
I am a beginner at MVP & one question strikes my mind:
isn't it simpler to create methods in Presenter, such as:
Save()
Start()
Stop()
and possible some events to which some view may subscribe.
instead of events in IView interface:
event SavePressed
event StartPressed
event StopPressed
and some methods which a presenter can call.
In this case Presenter is still separated from View level and capable of unit testing.
But also we eliminate the necessity to create IView interface and Presenter doesn't know anything about IView (explicitly, implicitly perhaps it will have to provide dome events such as StateChanged and so on).
thanks,
Ayrat
|
|
|
|
|
|
hi.
i work in Microsoft Visual Studio 2008 . i working in C# enviroment and creat a website project.
i want open picture with open dialog .please tell me who i can load picture with open dialog?
i am beginner .
please explain step to step.
whether i need a componet as toolbar?
please help me.
i need help body.
|
|
|
|
|
Don't cross post.
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
1. Put a File Upload control on your aspx page
2. When the user submits the page, save the selected file on the server.
3. In the postback code, create an image that points to the file you saved in step 2.
|
|
|
|
|
thank you. but what i write code in submit buttom?
|
|
|
|
|
Hi folks!
I have a Windows CE 5.0 device (Barcodereader with arm cpu) with WiFi.
I use .Net 3.5 on the CE and the PC.
VS2008 is the development environment.
I want to write a small program for CE which will read a barcode and an item count entry and send it to PC where the current (focused) app should receive a string like manual entry with the data.
First idea was remoting
CE does not support it.
Next idea is a WebService which works but I found no way to use SendKeys from within the WebService.
Is anybody out there with a solution or even with a better idea?
-Juergen
|
|
|
|
|
You cannot use SendKeys in a WebService. Services run under a different Desktop than what the user can see at the console.
You're CE app should be talking to a WebService that interacts with a database that your app and the normal app that the desktop is using interact with.
|
|
|
|
|
I have a class, with a method receiving objects and dealing with them accordingly.
But.... when a List object e.g List<MyObjectType> is passed to the method I want to be able to loop through the list and deal with each and every object within the list the same as I would have with a normal object.
How do I:
1. Recognize an object as a List?
2. Enumerate this list?
So far, I was able to recognize the object as being a list by doing the following (this is one for coding horrors):
if (pInputObject.GetType().FullName.Substring(0, 31).Trim() == "System.Collections.Generic.List") <br />
{<br />
.<br />
.<br />
.<br />
}
|
|
|
|
|
don't use strings to check for a specific type, it is expensive and inaccurate as it won't recognize derived types. The correct way is based on the is and as keywords.
Control c;
...
if (c is ListBox) log("c is a ListBox");
Label lbl=c as Label;
if (lbl!=null) log ("c is a label, text="+lbl.Text);
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
I'm not talking about controls, I'm talking about the generic List<T> object.
If I go with a generic class and use the is or as keywords I get stuck here:
if (pInputObject is List<Ti>) {<br />
foreach (Ti listObj in (List<Ti>)pInputObject) {<br />
<br />
}<br />
}
Ti is my class's generic Type.
|
|
|
|
|
an object is an object, a type is a type; whether it is a Control or a List<T> is irrelevant.
Here is proof:
public void Test() {
object obj=new object();
aha<int>.handleList(obj);
aha<double>.handleList(obj);
List<int> ints=new List<int>();
List<double> doubles=new List<double>();
aha<int>.handleList(ints);
aha<double>.handleList(ints);
aha<int>.handleList(doubles);
aha<double>.handleList(doubles);
}
public class aha<T> {
public static void handleList(Object arg) {
if (arg is List<T>) {
log("got List<T> as in "+arg.ToString());
} else {
log("did not get an expected list, got "+arg.ToString());
}
}
}
Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages
|
|
|
|
|
Have two overloads for your method, one that takes a MyObjectType and the other that takes a List<myobjecttype>. In the second method, iterate through the list and call the first method inside the loop. This should be a pretty clean solution.
|
|
|
|
|
Thank you for taking the time to read the actual question!
Before you posted this I conjured up a similar solution as to the one you are suggesting but ran into some trouble.
If I have an object (which is a list), let say (using simple types for argument sake), List<Forest> and I pass it to the overloaded method within a generic class (Type "Forest") as such: myListMethod(List<T> pListObject) .
The mentioned method is supposed to loop through all properties within each Forest and do the same for them, but what do I do if the List Object (List of Forest) has within itself, another List, say, List<TreeSpecie> .
When calling this method with a known List Type it was easy, but now I do not know the type of the object (TreeSpecie) within this list. How do I determine that type?
Regards
|
|
|
|
|
if ( whatever is IEnumerable )
{
// Iterate the items with foreach
}
else
{
// Normal
}
|
|
|
|
|
Hii i am writing a code to make the glass effect on windows form. Well the code works fine on vista but my target is on windows xp. I have copyed all the dll's that are reqired and when i debug i am getting an error "DLL NOT FOUND EXCEPTION UNHANDILED".
Here is the code that i am using:-
-----------------------------------------------------------------------------------------------------------------------------
This is the class where i import dwmapi dll.
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
namespace welcome_page
{
class VistaGlassEffect
{
internal class VistaApi
{
[DllImport("dwmapi.dll")]
internal static extern void DwmExtendFrameIntoClientArea(System.IntPtr hWnd, ref Margins pMargins);
[DllImport("dwmapi.dll")]
internal static extern void DwmIsCompositionEnabled(ref bool isEnabled);
internal struct Margins
{
public int Left, Right, Top, Bottom;
}
// consts for wndproc
internal const int WM_NCHITTEST = 0x84;
internal const int HTCLIENT = 1;
internal const int HTCAPTION = 2;
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
This the form where i call this class "VistaGlassEffect"
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.DirectX.AudioVideoPlayback;
using System.Diagnostics;
using System.Drawing.Drawing2D;
namespace welcome_page
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.FitGlass();
}
Video video;
private welcome_page.VistaGlassEffect.VistaApi.Margins marg;
private Rectangle topRect = Rectangle.Empty;
private Rectangle botRect = Rectangle.Empty;
private Rectangle lefRect = Rectangle.Empty;
private Rectangle rigRect = Rectangle.Empty;
private void FitGlass()
{
// If DWM is not enabled then get out
if (!this.IsGlassEnabled())
{
return;
}
// Set the Margins to their default values
marg.Top = 600; // extend from the top
marg.Left = 400; // not used in this sample but could be
marg.Right = 200; // not used in this sample but could be
marg.Bottom = 860;// not used in this sample but could be
this.Paint += new PaintEventHandler(this.Form1_Paint);
// call the function that gives us glass,
// passing a reference to our inset Margins
welcome_page.VistaGlassEffect.VistaApi.DwmExtendFrameIntoClientArea(this.Handle, ref marg);
}
private void apply()
{
this.Paint -= new System.Windows.Forms.PaintEventHandler(this.Form1_Paint);
this.RecreateHandle(); //needed if changing on the fly
this.FitGlass();
}
private bool IsGlassEnabled()
{
//if (Environment.OSVersion.Version.Major < 6)
//{
// Debug.WriteLine("How about trying this on Vista?");
// return false;
//}
//Check if DWM is enabled
bool isGlassSupported = false;
------welcome_page.VistaGlassEffect.VistaApi.DwmIsCompositionEnabled(ref isGlassSupported);---Here Error OCCURS.
return isGlassSupported;
}
// Alpha-blending Paint after the glass extension
// this seems better than the winforms transparency approach because here we can click on the glass!
private void Form1_Paint(object sender, PaintEventArgs e)
{
// black brush for Alpha transparency
SolidBrush blackBrush = new SolidBrush(Color.Black);
Graphics g = e.Graphics;
if (this.IsGlassEnabled())
{
// setup the rectangles
topRect = new Rectangle(0, 0, this.ClientSize.Width, marg.Top);
lefRect = new Rectangle(0, 0, marg.Left, this.ClientSize.Height);
rigRect = new Rectangle(this.ClientSize.Width - marg.Right, 0, marg.Right, this.ClientSize.Height);
botRect = new Rectangle(0, this.ClientSize.Height - marg.Bottom, this.ClientSize.Width, marg.Bottom);
// Fill Rectangles
g.FillRectangle(blackBrush, topRect);
g.FillRectangle(blackBrush, lefRect);
g.FillRectangle(blackBrush, rigRect);
g.FillRectangle(blackBrush, botRect);
}
blackBrush.Dispose();
}
protected override void WndProc(ref Message m)
{
base.WndProc(ref m);
if (m.Msg == welcome_page.VistaGlassEffect.VistaApi.WM_NCHITTEST // if this is a click
&& m.Result.ToInt32() == welcome_page.VistaGlassEffect.VistaApi.HTCLIENT // ...and it is on the client
&& this.IsOnGlass(m.LParam.ToInt32())) // ...and specifically in the glass area
{
m.Result = new IntPtr(welcome_page.VistaGlassEffect.VistaApi.HTCAPTION); // lie and say they clicked on the title bar
}
}
private bool IsOnGlass(int lParam)
{
// sanity check
if (!this.IsGlassEnabled())
{
return false;
}
// get screen coordinates
int x = (lParam << 16) >> 16; // lo order word
int y = lParam >> 16; // hi order word
// translate screen coordinates to client area
Point p = this.PointToClient(new Point(x, y));
// work out if point clicked is on glass
if (topRect.Contains(p) || lefRect.Contains(p) || rigRect.Contains(p) || botRect.Contains(p))
{
return true;
}
return false;
}
void buttn()
{
}
private void Form2_Load(object sender, EventArgs e)
{
int width = panel1.Width;
int height = panel1.Height;
System.Uri u = new Uri(@"F:\Documents\Viswa Teja\Documents\C2\teja.avi");
video = Video.FromUrl(u);
video.Owner = panel1;
video.Play();
panel1.Size = new Size(width, height);
//this.apply();
}
private void button1_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
-----------------------------------------------------------------------------------------------------------------------------
Please kindly help me.
|
|
|
|