|
I have a problem trying to zoom in on a bitmap i opened in a form.I couldnt find any simple code example that illustrates how to implement zooming from inside a program.I would appreciate if anyone can help me out.Please contact me at gehanmustafa@hotmail.com.
Yours,
Gehan Mustafa
|
|
|
|
|
gijoebijoe wrote:
Please contact me at gehanmustafa@hotmail.com.
No.
All you need to do is use DrawImage to draw the image at a larger than normal size.
Christian
I have drunk the cool-aid and found it wan and bitter. - Chris Maunder
|
|
|
|
|
Hi,
I'm having problems with issuing a SQL ExecuteNonQuery in my webService. It always returns an int with value -1.
I'm executing a stored procedure which should return a rowcount of the number of matching rows, which is 0 or 1. There is a matching row, so i should get 1 returned.
The code i am using is as follows:
--------------------------------------------------------------------------
string CnStr = "data source=localhost; Integrated Security=SSPI;Initial Catalog=Active";
SqlConnection sqlCn = new SqlConnection();
//Pass connection string to the SQLconnection object
sqlCn.ConnectionString = CnStr;
// Create a sqlcommand object to execute sql stored procedure
//pass query string and connection object to Command object
SqlCommand cmd = sqlCn.CreateCommand();
//Specify the Stored procedure to be executed
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "stp_Check";
//Create a Paramater object to provide input and return
cmd.Parameters.Add("@Mac", SqlDbType.Char,17);
cmd.Parameters["@Mac"].Value = strMAC;
//Open the connection
sqlCn.Open();
//Execute the query - return rowcount
int intMACAddressRows;
intMACAddressRows = cmd.ExecuteNonQuery();
-----------------------------------------------------------------------
If i execute the Stored procedure directly it works fine (i.e. one row is returned).
Thanks for any help you can give.
Cheers,
Colin
|
|
|
|
|
Update, Insert, and Delete commands will return the number of rows affected. Anything else returns -1.
creganc wrote:
If i execute the Stored procedure directly it works fine (i.e. one row is returned).
I'm unsure whether you mean the row is returned or the count of rows affected is returned when the procedure is executed directly. If you mean the actual row is returned, it is a Select statement and the return value will always be -1.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hi Charlie,
Thanks for the prompt response.
Sorry, should have said that the stored procedure is just issuing a select statement.
Ah, i thought the executenonquery would return the rowcount from the select.
As i only want to know if the row exists so should i use executescaler instead? Does that return the count as an int?
Thanks again for your help.
cheers,
Colin
|
|
|
|
|
ExecuteScalar returns an object which is the first column of the first row of the records returned. So, if the select statement is something like:
SELECT Count(*) FROM MyTable WHERE MyColumn = @MyParam you'd get the number of rows like this:
int rowCount = (int)command.ExecuteScalar();
Charlie
if(!curlies){ return; }
|
|
|
|
|
Thanks Charlie thats great.
Thanks for your help.
Cheers,
Colin
|
|
|
|
|
Hi,
I want to develop/use expense management tool similar to Microsoft's PocketPC Expense. I would like to create categories on the fly and data to be stored in xml for easy porting? Does any one has source code or ideas to do this?
Can any one point me to a open source for this?
|
|
|
|
|
I have a program that checks for the existence of a file and then reads the content, but I am running into a problem when I try to read, the file is still being written to. I have to ideas on how to solve, but unsure of the methods/syntax. I realize the solution is probably simple, but I'm failing to see it.....
1st - I can't find a property for the file or fileinfo class for 'locked', does such a method exist elsewhere? I am having trouble finding it.
2nd - I can catch the error, but can I in effect do a try {} catch {} re-try?
|
|
|
|
|
Use one of the larger overloads for the FileStream to request the access you want, as well as what access you want to share. If this is in conflict (you want write access but another process isn't sharing write access), an UnauthorizedAccessException will be thrown (this is documented for the FileStream class in the .NET Framework SDK).
If you want to continually try, you can use a simple loop but be careful. You might consider using a for loop with a set maximum number of tries before giving up, otherwise that thread of execution will block indefinitely:
FileStream file = null;
using (file)
{
while (true)
{
try
{
file = new FileStream("file.lock", FileMode.OpenOrCreate,
FileAccess.Write, FileShare.Read);
}
catch (UnauthorizedAccessException)
{
}
catch (Exception e)
{
break;
}
}
}
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
may be u can try this in a loop
FileInfo fi = new FileInfo(parm1);
bool fileIsLocked;
if ( fi.Exists )
{
fileIsLocked=false;
FileStream fileStream=null;
try
{
fileStream = fi.OpenRead();
fileStream = null;
}
catch(Exception)
{
fileIsLocked=true;
}
}
cool man
|
|
|
|
|
Please help me with this problem: I have a custom ToolBar control, which instantiates a PageSizeCbo, a custom server control which inherits from DropDownList. The ToolBar and the PageSizeCbo render on the page fine, but no events seem to fire.
Here is the ToolBar class:
<br />
<br />
using System;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
namespace QuoteBuilder_0_3.Controls.ToolBar {<br />
<br />
public class ToolBar : Control, INamingContainer {<br />
private System.Collections.ArrayList toolList = new System.Collections.ArrayList(10);<br />
public enum ToolType { PageSizeCbo=0 }<br />
<br />
public ToolBar() {}<br />
<br />
private void build () {<br />
Controls.Add(new LiteralControl("<div class='ToolbarContainer'>"));<br />
Table table = new Table();<br />
table.CssClass = "Toolbar";<br />
TableRow row = new TableRow();<br />
TableCell sepCell = new TableCell();<br />
sepCell.CssClass = "ToolbarSeparatorCell";<br />
sepCell.Controls.Add(new LiteralControl("|"));<br />
for (int i=0; i<toolList.Count; i++) {<br />
if (null == toolList[i])<br />
break;<br />
TableCell btnCell = new TableCell();<br />
btnCell.CssClass = "ToolbarButtonCell";<br />
btnCell.Controls.Add((Control)toolList[i]);<br />
row.Cells.Add(btnCell);<br />
row.Cells.Add(sepCell);<br />
}<br />
table.Rows.Add(row);<br />
Controls.Add(table);<br />
Controls.Add(new LiteralControl("</div>"));<br />
}<br />
<br />
public void AddTool (ToolType toolType) {<br />
switch (toolType) {<br />
case ToolType.PageSizeCbo:<br />
toolList.Insert((int)toolType, new PageSizeCbo());<br />
break;<br />
}<br />
}<br />
<br />
protected override void Render(System.Web.UI.HtmlTextWriter writer) {<br />
build();<br />
base.Render (writer);<br />
}<br />
<br />
protected override bool OnBubbleEvent(object source, EventArgs args) {<br />
Context.Response.Write("bubble handled!");<br />
return true;<br />
}<br />
}<br />
}<br />
And here is the PageSizeCbo:
<br />
using System;<br />
using System.Web.UI;<br />
using System.Web.UI.WebControls;<br />
<br />
namespace QuoteBuilder_0_3.Controls.ToolBar {<br />
public class PageSizeCbo : DropDownList, IToolBarTool {<br />
private const int TOTAL_OPTIONS = 5;<br />
private int [] pageSizeValues = new int[TOTAL_OPTIONS] { 0, 10, 25, 50, 100 };<br />
private string [] pageSizeDisplay = new string[TOTAL_OPTIONS] { "Unlimited", "10", "25", "50", "100" };<br />
<br />
public PageSizeCbo() : base() {<br />
SelectedIndexChanged += new EventHandler(PageSizeCbo_SelectedIndexChanged);<br />
Build();<br />
}<br />
<br />
public Control Build () {<br />
for (int i=0; i<TOTAL_OPTIONS; i++) {<br />
Items.Add(new ListItem(pageSizeDisplay[i], pageSizeValues[i].ToString()));<br />
}<br />
CssClass = "pageSizeCombo";<br />
EnableViewState = true;<br />
AutoPostBack = true;<br />
return this;<br />
}<br />
<br />
private void PageSizeCbo_SelectedIndexChanged(object sender, EventArgs e) {<br />
Context.Response.Write("Raising Bubble Event...<br/>");<br />
RaiseBubbleEvent(sender, e);<br />
}<br />
<br />
protected override bool OnBubbleEvent(object source, EventArgs args) {<br />
Context.Response.Write("Handling bubble from base cbo...");<br />
return false;<br />
}<br />
}<br />
}<br />
I am new to custom server controls, so any help would be very appreciated!
Thanks,
Brent
|
|
|
|
|
You should post this in the ASP.NET[^] forum.
Charlie
if(!curlies){ return; }
|
|
|
|
|
Hello,
i have a WebService on a Desktop-server and a MobileWebApplication for a PocketPc. Now i want to extend this MobileWebApplication in that way, that when the user is on certain place the Application is noticed the user with some information. Do i here need a GPS System or can i reached this things with WLAN? and/or is this difficult to implement?
thanks in advance
regards
|
|
|
|
|
Yes, you need GPS. GPS data is not difficult to parse, but communication may depending on your device. Be sure to get a GPS that is NMEA 2.0 compatible, which most these days are. It's a simple text format that you can find lots of information about on the web by performing a search.
MSDN Online Library[^] has some articles, and you could always google[^] as well.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I want my C# program can cut some region of a picture,
What should I do in MouseDown, MouseMove, MouseUp Event,
to select the scale of the picture I want to cut,
Is there any sample...??
Thanks !!
|
|
|
|
|
When width and height are Changed of my program, How can I get the width and height of my program.
I see a code in example from a book but I'm not sure
code is start with like this
protected override void OnResize(EventArgs ea)
What deligate or event need to get Size Changed event.
and How can I get width and height of my program when it occurs?
Image will remind us some feelings and if I can ask someone about a problem, that's not a bad life.
|
|
|
|
|
form.Width
form.Height
A quick look at the object properties in VSS would have answered your question.
This signature left intentionally blank
|
|
|
|
|
I'm trying to caputre Logitech's USB gamepad using DirectInput with the following code. I use a timer to poll the gamepad's state. It seems the gamepad is captured but the buttons are not as I always get:
X: 32767
Y: 32767
Any ideas what could be the problem? Thanks in advance.
public class InputHandler
{
protected Device gamepad = null;
public InputHandler(Control Owner)
{
foreach (
DeviceInstance di in
Manager.GetDevices(DeviceClass.GameControl, EnumDevicesFlags.AttachedOnly))
{
if (di.DeviceType == DeviceType.Joystick)
{
gamepad = new Device(di.InstanceGuid);
break;
}
}
gamepad.Properties.AxisModeAbsolute = true;
gamepad.SetCooperativeLevel(Owner,
CooperativeLevelFlags.Foreground |
CooperativeLevelFlags.NonExclusive);
gamepad.Acquire();
}
public JoystickState GetGamepadState()
{
return gamepad.CurrentJoystickState;
}
}
private void tmrPollInput_Tick(object sender, System.EventArgs e)
{
InputHandler input = new InputHandler(this);
JoystickState padstate = input.GetGamepadState();
byte [] buttons = padstate.GetButtons();
string info = "";
for (int i = 0; i < buttons.Length; i++)
{
if (buttons[i] != 0)
info += "Button: " + i + "\r\n";
}
txtGamepad.Text = "X: " + padstate.X + "\r\n"
+ "Y: " + padstate.Y + "\r\n"
+ info;
}
|
|
|
|
|
I'm not sure I completely understand your problem, but keep in mind that sticks by default give you a delta, not a position. If you move the stick right, for example, you'll get deltaX=+1, deltaY=0 for a small change (it's weighted against the amount of movement).
I don't currently have the Managed DX9 SDK installed on this machine, so I'm sorry I can't give you more help.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
I am trying to make C++ api calls from my C# code. I don't know how to properly define my data structure in C# so that data can be properly marshalled. Here is how in C++ api and struct are defined:
*****C++ code ********
...........
typedef struct {
char uid[20]; // Max Len: xx
char *data; // Data on Tag
int len; // Data length
} DataBuffer;
class AFX_EXT_CLASS cObject
{
public:
bool ReadData(DataBuffer* RetVal, int iTime);
cObject();
virtual ~cObject();
private:
DataBuffer* mBufferData;
};
....
********End C++ code ***************************
Here is C# code i tried but failed
*********C# code ***************************8
....
namespace MyCAPI
{
[StructLayout(LayoutKind.Sequential)]
public struct DataBuffer
{
public StringBuilder uid; // Max Len: xx
public StringBuilder data; // Data on Tag
public int len; // Data length
}
/// <summary>
/// Summary description for Class1.
/// </summary>
public class CAPI
{
[DllImport("Cobject.dll")]
public static extern bool ReadData(ref DataBuffer RetVal, int iTime);
}
}
....
**********END OF C#*******************
Please advise. Thanks
Kevin
|
|
|
|
|
You should read Interop Marshalling[^] in the .NET Framework SDK to understand the differences in data types.
The struct is fairly straight-forward to marshal. Keep in mind that an unmanaged char is ANSI, so you must declare CharSet.Ansi (default for P/Invoke with C#, but still a good idea to set) and that a native int is actually an IntPtr in managed code, since it's platform-dependent:
[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Ansi)]
public struct DataBuffer
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst=32)] public char[] uid;
public string data;
public IntPtr len;
} IntPtr has constructors and other methods that will help wrap a managed int (Int32 ) or long (Int64 ). This is an important distinction because if you compile your native code for 64-bit platforms, the 64-bit signature is used. If you don't, your application will run under WOW64, a 32-bit emulator and IntPtr should still be 32 bits. If you don't plan on supporting a 64-bit native API, then you can change IntPtr both here and below to simply an int . Keep in mind that no one can predict the future, though. Declaring your fields, properties, and params as IntPtr now may save you time in the future if you ever do decide to recompile your native app/library for the 64-bit platforms.
The class is a different subject, though. A C++ class does not use C-style exports like most of your export functions would (should). You need to P/Invoke these using the CallingConvention.ThisCall calling convention. You declare your methods (member functions) with a 'this' pointer as the first parameter, as documented in the .NET Framework SDK for the CallingConvention enumeration.
So, ReadData becomes:
[DllImport("cobject.dll", CallingConvention=CallingConvention.ThisCall)]
extern static bool ReadData(ref DataBuffer RelVal, IntPtr iTime); Never declare P/Invoke methods as public, unless the defining class is internal. C and C++ give direct access to memory - the CLR does not (that's why it's call "managed"). P/Invoke requires unmanaged permissions to be granted to the assembly based on it's evidence and that's one level of protection. But trust only goes so far. Never let unknown code call P/Invoke functions because you should never trust your callers. If the P/Invoke function is private (lack of an access modifier in C# defines it as private), then only your class can makes calls to it. And don't let others classes in your library call it either, unless it's necessary. Calling the method incorrectly does not require malicious intent.
Finally, the ThisCall calling convention requires a class factory. You need to have an instance of that class to pass as the first parameter.
I have covered this in previous messages, so I redirect you to http://www.codeproject.com/script/comments/forums.asp?msg=771919&forumid=1649#xx771919xx[^] for more information.
This posting is provided "AS IS" with no warranties, and confers no rights.
Software Design Engineer
Developer Division Sustained Engineering
Microsoft
[My Articles]
|
|
|
|
|
Hi there,
is there a way of specifying the order of Tests within a given TestFixture (class)?
It seems that the order how they appear in the nDoc GUI is alphabetically, but can I rely on this?
Thanks in advance,
Matthias
If eell I ,nust draw to your atenttion to het fakt that I can splel perfrectly well - i;ts my typeying that sukcs.
(Lounge/David Wulff)
www.emvoid.de
|
|
|
|
|
Matthias Steinbart wrote:
is there a way of specifying the order of Tests within a given TestFixture (class)?
Using the Advanced Unit Test program (shameless plug) you can sequence tests, and also test what happens when processes are executed out of sequence. See sig.
Marc
MyXaml
Advanced Unit Testing
|
|
|
|
|
In an ideal world, tests should be able to successfully run independently of their ordering.
However, this is the real world. If you have a bunch that you really really absolutely have to run in order, then I would say to make a test that just calls the other tests, in order.
Alternatively, create Setup and Teardown subs that prepare the way for (and clean up after) each test.
my blog
|
|
|
|
|