|
I tried
EnableViewState = true
not working
|
|
|
|
|
I ask about this they told it's not possible
I Wish the Life Had CTRL-Z
|
|
|
|
|
|
Hi,
Does anyone know if it's possible to change the OS color Depth/Quality via a C# program?
Thanks,
Joe
|
|
|
|
|
I know of no way to do it in managed code.
I once did resolution changes with C# code by calling good old Win32 functions
(such as EnumDisplaySettings and ChangeDisplaySettings from user32.dll).
This requires the use of PInvoke and is not that simple...
Also it is considered bad practice for one application to change system settings
that affect all current and future applications.
Are you sure you want this ?
In the special case where one application is monopolizing the screen (e.g.
a full screen game), there are ways to do it using DirectX (for which a managed SDK
exists); I never did this tho.
Luc Pattyn
|
|
|
|
|
how to do this in C# ???
i get an error when i put the ref int m_param in the C# struct
What i'm doing wrong here
The ideia is the class be intatiated do some work , ant then put
the result int the refrence saved in the m_retParam.
--------------
C++
----
class A<br />
{<br />
int m_retParam&<br />
A(int ¶m) : m_retParam(retParam){<br />
}<br />
public void DoSomething(){<br />
m_retParam = 5;
}<br />
}
--------------
C#
----
class A<br />
{<br />
ref int m_retParam; :doh: <----------- Compilter error<br />
<br />
A(ref int param) {<br />
m_retParam=param;<br />
}<br />
public void DoSomething(){<br />
m_retParam = 5;
}<br />
}
|
|
|
|
|
I would expect the ref keyword only in argument lists, where it is typically used to
pass a reference rather than a value for value types, so the method called can
modify them (a variant of this is "out"). But no "ref" in a struct or class.
Luc Pattyn
|
|
|
|
|
Thanks for yor response .
How can i solve this in C#
can you give me a sugestion?
|
|
|
|
|
So you cant write
class A {
ref int m_retParam;
A(ref int param) {
m_retParam=param;
}
public void DoSomething(){
m_retParam = 5;
}
}
but you can write
class A {
public A() {}
public void DoSomething(ref int m_retParam) {
m_retParam = 5;
}
}
or
class A {
public int result;
public A() {}
public void DoSomething() {
result = 5;
}
}
the result now is available as A.result
or
class A {
private int result;
public int Result {get {return result;}}
public A() {}
public void DoSomething() {
result = 5;
}
}
the result now is available as A.Result
or, more in the way you would like it I guess, but with an extra class:
class B {
public int result;
public B() {}
}
class A {
private B m_retObject;
public A(B retObject) {
m_retObject=retObject;
}
public void DoSomething() {
m_retObject.result = 5;
}
}
the result now is available as B.result
(providing a B.Result property probably doesnt make much sense, since
it needs a getter for the caller, and a setter for class A, so it could as
well be public in the first place.
One of the above should suit almost every requirement.
Cheers.
Luc Pattyn
|
|
|
|
|
Thanks for your complete response
I think i will use the last example.
I Wonder why old simple things get so complicated in C# ...
|
|
|
|
|
It's all about safety.
Pointers are considered unsafe:
- if you can modify them (e.g. increment to scan an array), you may get outside
the valid range
- even if you cant, you might point to something that isnt alive anymore
(unless the CLR understands it really is a reference to an object, i.e. something
the CLR knows it is alive, and that is exactly what my class B is all about).
So C# offers you the following way to return results:
- through the return value of a method
- through an out or ref method parameter
- through an event (think of it as a callback function with input arguments)
each of these can be primitive values or aggregates (classes or structs).
Similar things hold true for delegates, which are basically function pointers
associated with a specific object.
Cheers,
Luc Pattyn
|
|
|
|
|
That code isn't possible in C#, you can't use a local field as a reference to an exisiting int, and then change it in some other method.
The ref parameter does allow you to modify the original calling instance, but not the way you want it.
|
|
|
|
|
Thanks for yor response .
How can i solve this in C#
can you give me a sugestion?
|
|
|
|
|
I have a form which contains a tab control, which contains two tab pages.
On each tab page, there is a DataGridView, bound to it's own DataTable.
In the RowsAdded event handler for both DGVs, when the first row is added, I resize the columns to fit the data. My handler looks something like this:
private void dgvAllEvents_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)<br />
{<br />
...<br />
dgvAllEvents.AutoResizeColumn(0, DataGridViewAutoSizeColumnMode.DisplayedCellsExceptHeader);<br />
}<br />
<br />
This code works fine for the datagridview that is visible - that is, on the selected tab. However, the column does not get resized on whichever dgv is NOT visible - the tab page that is not selected.
The event is getting fired, I have confirmed that. But the column is not resized when the AutoResizeColumn method is called.
Is there an optimization here that prevents resize from being executed if the column is not visible?
Thanks for any insight you have here.
|
|
|
|
|
I have a bitmap file which I can load into a Bitmap object (or not if i don't have to), but I also have a number of smaller bitmap objects whose images should be sections of the larger image. The co-ordinates (top left, bottom right) of the sections I would like to take are known. I can do this by looping through every pixel needed, using the getPixel method on the larger bitmap, then the setPixel method on the smaller bitmap, however this seems a little bodged, and is probably a bit slow. Is there a better way to do this?
Thanks for any help.
|
|
|
|
|
Still a bit new to the programming, but it looks like the Bitmap.Clone Method is what you might be looking for?
<code>
Bitmap bmpOriginal, bmpSection;
bmpOriginal = new Bitmap("C:\\Test.bmp");
bmpSection = bmpOriginal.Clone(new Rectangle(0, 0, 100, 100), bmpOriginal.PixelFormat);
</code>
-- modified at 16:12 Saturday 6th January, 2007
|
|
|
|
|
you can do the following:
Bitmap newBitmap=new Bitmap(of the right size);
Graphics g=Graphics.FromImage(newBitmap);
and now you can draw anything you like into g, including (part of) an existing image.
Luc Pattyn
|
|
|
|
|
wondering if anyone has some C# code that can verify if SQL is ANSI complaint or not.
tj
|
|
|
|
|
Why does it need to be C# ?
What DB are you using ? Perhaps it has a full ANSI only mode ?
Christian Graus - Microsoft MVP - C++
Metal Musings - Rex and my new metal blog
|
|
|
|
|
Hi,
I have an unmanaged C++ class, and a managed c++ wrapper for the class. I then access the managed c++ from c# client. The whole thing compiles fine, but when I run the c# client, it crashes as soon as it hits the line where the managed c++ object is initialized. Here is the code that I am working with:
#include <windows.h>
#include <vcclr.h>
#using <System.dll>
using namespace System;
class UnManagedClass
{
public:
LPCWSTR GetPropertyA() { return 0; }
void MethodB ( LPCWSTR ) {}
};
public ref class AdapterNET
{
private:
UnManagedClass * m_unman;
public:
AdapterNET() : m_unman( new UnManagedClass ) {}
~AdapterNET() { delete m_unman; }
protected:
!AdapterNET() { delete m_unman; }
public:
property String ^ get_PropertyA
{
String ^ get()
{
return gcnew String( m_unman->GetPropertyA() );
}
}
void MethodB( String ^ aString )
{
pin_ptr<const WCHAR> str = PtrToStringChars( aString );
m_unman->MethodB( str );
}
};
using System;
using System.Collections.Generic;
using System.Text;
namespace TestingAdapterNET
{
class AdapterNETDriver
{
static void Main( string[] args )
{
AdapterNET _adapterNET = new AdapterNET();
string propA = _adapterNET.get_PropertyA;
_adapterNET.MethodB( propA );
}
}
}
Any ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi
1) what is "crashes here", what are the symptoms ? any error message, message box, ... ?
2) try putting your managed code inside a try-catch construct, and when you catch
an exception entirely display it. (hint: the Exception.ToString() method gives it all).
3) BTW, how is your C# code to find adapterNET, arent you missing a using statement ?
Luc Pattyn
|
|
|
|
|
Hi and thanks for the response.
1) Crashes here means that I get the following:
No symbols are loaded for any call stack frame. The source code cannot be displayed.
with exception:
{"The specified module could not be found. (Exception from HRESULT: 0x8007007E)":null}
2) I added the try/catch, but it never hits it
3) I included a reference to the dll, and it seems to find the class (since intellisense is available). I have wrapped the c++ code with a namespace and am now '#using' it, just in case.
Any more ideas?
Thanks,
-----------------
Genaro
|
|
|
|
|
Hi,
HRESULT ending on 007E means good old ERROR_MOD_NOT_FOUND, so module not found,
meaning a needed dll file is not found at run-time
If I understand correctly you are using three modules:
1. your main program (C#), being an EXE file
2. your managed C++ adapter class in a DLL
3. your unmanaged C++ whatever, in another DLL
unfortunately it is not clear which module is not found.
I guess (and hope) you have 1. and 2. as two projects within a single solution
in Visual Studio, so it should be perfectly possible to single-step as long as
you do not access anything in 3.
to make sure the managed C++ works, add another class to it, something
that does not need 3. (e.g. a simple function that returns the sum of two integers)
and try using that first;
if that succeeds, continue with the adapter itself.
Luc Pattyn
|
|
|
|
|
I actually have 2 and 3 combined... both managed and unmanaged c++ in the same dll.
I added another managed class to the dll, which just returns the sum of two numbers and does not access any managed code, but I get the same error.
Thanks,
-----------------
Genaro
|
|
|
|
|
Gee, I was not even aware you could do that... But then, I dont use C++, I use
either C#, or C# + unmanaged C with PInvoke.
Maybe the presence of unmanaged code prevents you from calling the managed half of
that mixed dll ??
Luc Pattyn
|
|
|
|