|
thank you. i read it and implemented it. however, everytime i try to compile, it gives me an error
"needs an object reference for the nonstatic method 'nsClearConsole.ClearConsole.Clear()'"
so i created an object:
nsClearConsole.ClearConsole cls = new nsClearConsole.ClearConsole();
then i used it:
cls.Clear();
but when i compile, it says something about cls not being a namespace or class (did you miss a using or assembly reference?) or something like that...
any help?
|
|
|
|
|
Are you trying to write this as a singleton class? The following works for me:
using System;
using System.Runtime.InteropServices;
namespace Example
{
class ConsoleClass
{
private const int STD_OUTPUT_HANDLE = -11;
private const byte EMPTY = 32;
private int hConsoleHandle;
public ConsoleClass()
{
hConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
}
[StructLayout(LayoutKind.Sequential)]
struct COORD
{
public short x;
public short y;
}
[StructLayout(LayoutKind.Sequential)]
struct SMALL_RECT
{
public short Left;
public short Top;
public short Right;
public short Bottom;
}
[StructLayout(LayoutKind.Sequential)]
struct CONSOLE_SCREEN_BUFFER_INFO
{
public COORD dwSize;
public COORD dwCursorPosition;
public int wAttributes;
public SMALL_RECT srWindow;
public COORD dwMaximumWindowSize;
}
[DllImport("kernel32.dll", EntryPoint="GetStdHandle", SetLastError=true,
CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int GetStdHandle(int nStdHandle);
[DllImport("kernel32.dll", EntryPoint="FillConsoleOutputCharacter", SetLastError=true,
CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int FillConsoleOutputCharacter(int hConsoleOutput,
byte cCharacter, int nLength, COORD dwWriteCoord,
ref int lpNumberOfCharsWritten);
[DllImport("kernel32.dll", EntryPoint="GetConsoleScreenBufferInfo", SetLastError=true,
CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int GetConsoleScreenBufferInfo(int hConsoleOutput,
ref CONSOLE_SCREEN_BUFFER_INFO lpConsoleScreenBufferInfo);
[DllImport("kernel32.dll", EntryPoint="SetConsoleCursorPosition", SetLastError=true,
CharSet=CharSet.Auto, CallingConvention=CallingConvention.StdCall)]
private static extern int SetConsoleCursorPosition(int hConsoleOutput, COORD dwCursorPosition);
public void Clear()
{
int hWrittenChars = 0;
CONSOLE_SCREEN_BUFFER_INFO strConsoleInfo = new CONSOLE_SCREEN_BUFFER_INFO();
COORD Home;
Home.x = Home.y = 0;
GetConsoleScreenBufferInfo(hConsoleHandle, ref strConsoleInfo);
FillConsoleOutputCharacter(hConsoleHandle, EMPTY,
strConsoleInfo.dwSize.x * strConsoleInfo.dwSize.y, Home, ref hWrittenChars);
SetConsoleCursorPosition(hConsoleHandle, Home);
}
}
class Demo
{
[STAThread]
static void Main(string[] args)
{
ConsoleClass ClearMyConsole = new ConsoleClass();
Console.WriteLine("THIS IS FIRST LINE");
Console.ReadLine();
ClearMyConsole.Clear();
Console.WriteLine("THE CONSOLE WAS CLEARED");
Console.WriteLine("Hit Enter to Terminate");
Console.ReadLine();
}
}
}
- Nick Parker My Blog | My Articles
|
|
|
|
|
im using it as a .dll to another file.
using nsClearConsole;
and then i called it with a nsClearConsole.ClearConsole object called "cls".
cls.Clear();
am i doing something wrong?
|
|
|
|
|
You can compile it separately, that's not a problem. nsClearConsole should be the namespace (for your example), and as long as you have included a reference to that assembly and included the using nsClearConsole; within your code you should be fine. You don't need to prefix the ClearConsole class with nsClearConsole unless you are using another namespace somewhere that contains a ClearConsole class (unlikely).
- Nick Parker My Blog | My Articles
|
|
|
|
|
thank you for your patience. as it turns out, it was my own stupidity for the errors. my problem was i was calling the Clear() method in another method, not Main(), where i had created the cls object.
its late, im tired, stupid mistake, dont know why i didnt see it, i just created the object inside the new method.
thank you very much!
ip
and thanks for the namespace.class abbreviation... i must be dead tired... not thinking straight...
|
|
|
|
|
Hi,
I have the code below to draw an image:
Rectangle rect = new Rectangle(100,100,110,180);
g.DrawImage(this.pictureBox1.Image, rect);
I notice that the image will keep within the constraints I've set (110,180), but the image will distort. Is there a way to have the image reduce proportionately?
Thanks,
Ron
|
|
|
|
|
myNameIsRon wrote:
Is there a way to have the image reduce proportionately?
You can use the GetThumbnailImage method of the Image class. There is an example on MSDN here[^].
- Nick Parker My Blog | My Articles
|
|
|
|
|
please help me ,howa can I find Activeskin skins...
how can I download it.....?
Ahmed Gaser
|
|
|
|
|
Like everything else: google[^].
This forum is for questions about C# and using it in projects; not about specific projects (even if Activeskin is written in C#) or products.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
where can I write this post....?
I searched google and fined nothing.
If you can help me....
Ahmed Gaser
|
|
|
|
|
Hi, when I try to read in data to a dataset and the table name has a space in it, I get an exception that the table doesn't exist. For some reason, only the part of the table name up to the space is recognised. Do I need to escape the space in a special way or try some other method? Thanks.
...code....
String sTable = "Table space".
dataAdapter.File(dataSet,sTable); //exception here...., tries to load "Table"
"Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.
|
|
|
|
|
Spaces in database object names are a terrible idea, use _ in future. For now, I believe that wrapping the name in square brackets will fix the problem. I know that works for reserved names. If I am wrong, try single quotes, but that seems a lot less likely to me.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi, thanks, it's not my data file, so I can't control the use of spaces. I've tried wrapping it in square brackets, but it still throws an exception and seems to ignore the part of the name after the space, also does this if I replace the space with an underscore, quite weird.
"Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.
|
|
|
|
|
Hi, that suggestion of yours worked great, I'd just put it in after the necessary place in the code. Thanks heaps.
"Ergo huffabo et puffabo et tuam domum inflabo" ait magnus malus lupus.
|
|
|
|
|
No worries. The _ will only work if the table is named that way to start with, you can't use one for the other The [] is generally a good way to show SQL what you mean when it's not clear, for example if you name a table Index, it won't work without the [] to show that the reserved word is meant as a name.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi,
I am trying to create a word 2003 document thru a windows application written in C#. I have added a reference of the Microsoft Word 11.0 Object library to my project.
Thing is that the below line of code is causing an error "The type or namespace name 'Word' could not be found (are you missing a using directive or an assembly reference?)"
private Word.ApplicationClass WordApp = new Word.ApplicationClass();
This is the main line where the Word document creation starts. I dont get this error when using Microsoft Word 9.0 Object library (Word 2000).. but the requirement is for Word 2003 automation.
I am not using Visual Tools for Office 2003. Is there any other way to create word 2003 documents?
Thanks in advance
sundancer
|
|
|
|
|
You should always use the PIAs (Primary Interop Assemblies) for Office when possible. Visual Tools for Office 2003 (.NET programming support comes on the Office 2003 Professional CD) and the downloadable Office XP PIAs are what you should use. In fact, if you want to support both Office XP and 2003, use the Office XP PIAs which you can download from MSDN[^]. Typelibs are typically forward-compatible but not always backward compatible. In fact, for most basic functionality even typelibs from Office 97 should support 97, 2000, XP (2002) and 2003 versions of Office products.
In any case, though, the problem is that you aren't referencing the namespace correctly. The namespace is not simply "Word". It's most likely "Microsoft.Office.Interop.Word". At the top of your source file along with all the other using statements, type using then hit Alt+J to display the namespaces.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
i recently downloaded the source code for the WinConsole, by Wesner Moise. (http://www.codeproject.com/csharp/winconsole.asp). I have the source codes, but i'm not sure how to compile them.
at the command line, i've tried different ways:
csc WinConsole.cs
csc /t:library WinConsole.cs
csc /r:ConsoleWriter.cs WinConsole.cs
all i get is errors like "no entry point defined" and "ERROR CS0246: The type or namespace name 'ConsoleWriter' could not be found (are you missing a using directive or an assembly reference?)"
i'm not sure what to do. in the folder i downloaded with all the sources, i have the following files:
bin (dir)
obj (dir)
App (icon)
AssemblyInfo.cs
ConsoleWriter.cs
Main.cs
WinConsole.cs
WinConsole.csproj
WinConsole.csproj.user
Can someone help me?
|
|
|
|
|
It looks like the download contains essentially two parts: the WinConsole class and the ConsoleWriter helper class to help redirect trace output, which are implemented in WinConsole.cs and ConsoleWriter.cs respectively, and a test program implemented in Main.cs with assembly data in AssemblyInfo.cs .
To build the test program, either use Visual Studio to open the WinConsole.csproj , or build on the command line like so:
csc /t:winexe /win32icon:app.ico assemblyinfo.cs ConsoleWriter.cs Main.cs WinConsole.cs To use in your own application, you can either include the source files in your project, or you could build WinConsole as a DLL:
csc /t:library /out:WinConsole.dll WinConsole.cs ConsoleWriter.cs
Stability. What an interesting concept. -- Chris Maunder
|
|
|
|
|
i get it now. thank you very much.
i didnt know about the icon feature. nice
thanks,
ip
|
|
|
|
|
Hi,
im just start designing a new WinForms app, and i'm not sure if the .NET built-in data binding via DataView etc. is the right tool for the job.
The application will read and write its data from/to an XML file (multiple versions must be supported, at least for reading).
The XML structure is not very "relational", it is more a document (in the sense of a Word document) than a database (tablular data).
I'm coming from the Java world, and used a ValueModel style data binding with great success. More details about the ValueModel data binding style can be found at http://c2.com/ppr/vmodels.html and http://c2.com/cgi/wiki?ModelViewControllerHistory.
With a ValueModel data binding, i would read the XML File in an object, put that in a ValueHolder, and would wire all widgets with AspectAdapters, SelectionInList, ...
This would provide me with a bi-directional binding, and usinge the BufferedValueHolder i would even get a buffering for free.
My question to the WinForms gurus:
- is the DataView data binding flexible enough, even if my data is more a document than a table?
- can i bind a text field bi-directional to a property of an arbitrary object?
- does the DataView data binding work when the widgets are on different forms?
- what's hard with DataView data binding, what style of binding requirements should be avoided?
Bye,
Jürgen
|
|
|
|
|
zet wrote:
is the DataView data binding flexible enough, even if my data is more a document than a table?
No, it is not. A DataView is created over a DataTable , which is a class used within a DataSet (any of which don't require you to use a DataView , but they will be more limited in functionality since the DataView supports filtering, sorting, etc.). A DataSet XML schema consists of 2- to 3-level elements (tabular data, as you said).
zet wrote:
can i bind a text field bi-directional to a property of an arbitrary object?
Yes; see the PropertyManager class in the .NET Framework SDK for more information. This is used in the same manner as the CurrencyManager class, which are both derivatices of the BindingManagerBase which is used by the Control.BindingContext property. Use the Control.DataBindings collection property to add bindings to objects (like another TextBox ) for properties (like the Text property of your two TextBox es).
zet wrote:
does the DataView data binding work when the widgets are on different forms?
A DataView is simply a class. So long as the instance is accessible on different forms, the controls can bind to them. The import thing to realize is that a BindingContext must bind to the exact same object and member name (like a DataSet and one of its table names, or just the DataTable itself).
--
There is nothing really provided in the .NET BCL (base class library) that provides the sort of binding you're asking for, but that's not to say it isn't possible (anything is possible when comparing Java and .NET, it's just that the JRE contains/lacks some stuff that .NET doesn't/does have).
This also sounds quite a bit like the MVC pattern (Model-View-Controller), or at least it would fit. CodeProject has several good articles about MVC, including Declarative Programming Of The MVC Pattern Within The Context Of DataBinding[^].
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
I have a project that was written in VB6 and which I need to re-design in C#. It uses a number of MSHFlexGrids that have had the header height expanded to fit two lines of text. Is there a grid control available in C# that will allow me to change the header width?
|
|
|
|
|
Not in the base class library (BCL), no. The DataGrid is the closest thing to the FlexGrid component, but does not expose APIs for owner-drawing the headers.
I suggest you take a look at some third-part controls like XtraGrid[^]. Many other third-party controls are available to use, but I've used this one and it works well.
Microsoft MVP, Visual C#
My Articles
|
|
|
|
|
This is really starting to piss me off. Someone please prove me wrong.
Here is a link to the function in DX 9 sdk.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/directx/graphics/reference/d3dx/functions/texture/d3dxsavesurfacetofile.asp
Following dll's are referenced in my program.
Microsoft.DirectX.dll
Microsoft.DirectX.Direct3D.dll
Microsoft.DirectX.Direct3DX.dll
The code:
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
.
.
//here trying to call D3DXSaveSurfaceToFile
//the parameters are wrong but thats not the problem
D3DXSaveSurfaceToFile();
The eror I get: "The name does not exist in MainFrom..." bla bla
In other words, I cannot locate the function. Where is it?
Please help.
If it helps, here is the link to what I am trying to do. The only problem the link is in C++.
http://www.codeproject.com/dialog/screencap.asp#And%20The%20DirectX%20way%20of%20doing%20it%20:
Thanks in advance.
|
|
|
|
|