|
The parameter is a way of identifying a particular synchronization scope. It must be visible to every method that participates in that synchronization. It is usually declared in a class as:
class UsesSynchronization
{
private Object key = new Object();
public SafeMethod()
{
lock( key )
{
...
}
}
}
It must be a reference type because a value type would be boxed in a different object for each call to lock , which is actually syntactic sugar for Monitor.Enter and Monitor.Exit .
Nick
----------------------------------
Be excellent to each other
|
|
|
|
|
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.Office.Interop.Excel;
using System.Windows.Forms;
using System.Reflection;
namespace testtesttestExcel
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
//Declare these two variables globally so you can access them from both
//Button1 and Button2.
Microsoft.Office.Interop.Excel.Application objApp;
Microsoft.Office.Interop.Excel._Workbook objBook;
Microsoft.Office.Interop.Excel.Workbooks objBooks;
Microsoft.Office.Interop.Excel.Sheets objSheets;
Microsoft.Office.Interop.Excel._Worksheet objSheet;
Microsoft.Office.Interop.Excel.Range range;
private void button1_Click(object sender, System.EventArgs e)
{
try
{
// Instantiate Excel and start a new workbook.
objApp = new Microsoft.Office.Interop.Excel.Application();
objBooks = objApp.Workbooks;
objBook = objBooks.Add(Missing.Value);
objSheets = objBook.Worksheets;
objSheet = (Microsoft.Office.Interop.Excel._Worksheet)objSheets.get_Item(1);
//Get the range where the starting cell has the address
//m_sStartingCell and its dimensions are m_iNumRows x m_iNumCols.
range = objSheet.get_Range("A1", Missing.Value);
range = range.get_Resize(5, 5);
//Create an array.
double[,] saRet = new double[5, 5];
//Fill the array.
for (long iRow = 0; iRow < 5; iRow++)
{
for (long iCol = 0; iCol < 5; iCol++)
{
//Put a counter in the cell.
saRet[iRow, iCol] = iRow * iCol * iCol;
}
}
//Set the range value to the array.
range.set_Value(Missing.Value, saRet);
objApp.Visible = true;
objApp.UserControl = true;
}
catch( Exception theException )
{
String errorMessage;
errorMessage = "Error: ";
errorMessage = String.Concat( errorMessage, theException.Message );
errorMessage = String.Concat( errorMessage, " Line: " );
errorMessage = String.Concat( errorMessage, theException.Source );
MessageBox.Show( errorMessage, "Error" );
}
Microsoft.Office.Interop.Excel.Range currentFind = null;
Microsoft.Office.Interop.Excel.Range firstFind = null;
string A = "16";
// You should specify all these parameters every time you call this method,
// since they can be overridden in the user interface.
currentFind = objSheet.Cells.Find(A, Type.Missing,
Microsoft.Office.Interop.Excel.XlFindLookIn.xlValues, Microsoft.Office.Interop.Excel.XlLookAt.xlWhole,
Microsoft.Office.Interop.Excel.XlSearchOrder.xlByRows, Microsoft.Office.Interop.Excel.XlSearchDirection.xlNext, false,
Type.Missing, Type.Missing);
while (currentFind != null)
{
// Keep track of the first range you find.
if (firstFind == null)
{
firstFind = currentFind;
//textBox1.Text = currentFind.get_Address(true, true, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, false, Missing.Value);
}
// If you didn't move to a new range, you are done.
else if (currentFind.get_Address(Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing)
== firstFind.get_Address(Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlReferenceStyle.xlA1, Type.Missing, Type.Missing))
{
break;
}
currentFind.Font.Color = System.Drawing.ColorTranslator.ToOl
(System.Drawing.Color.Red);
currentFind.Font.Bold = true;
currentFind = objSheet.Cells.FindNext(currentFind);
}
}
}
After finding the cell containing "16", i want to write in string data to the right of it. how should i go about doin this. I did some research on the codes, but i kept getting errors. Please advise me on my problem. Thanks alot!!
|
|
|
|
|
Hi,
How can I pass a Guid as a Parameter? I have the following method in my DAL but I cannot pass the value as Guid and I don't know how to do the conversion. I get this error "Specialized cast in not valid".
My method looks like this:
public dsWBGT GetPersonByUserId(Guid userId)
{
dsWBGT dsPerson = new dsWBGT();
WBGT.DAL.dsWBGTTableAdapters.PersonTableAdapter taPerson = new WBGT.DAL.dsWBGTTableAdapters.PersonTableAdapter();
taPerson.FillByUserId(dsPerson.Person, UserId);
return dsPerson;
}
Basically I am using ASPNET as the membership provider and I need to retrieve the user details based on the userID.
This is my method:
public void GetPersonByUserId()
{
frmUsers usersForm = frmUsers.GetChildInstance();
this.dsWBGT = personDataManager.GetPersonByUserId(UserId);
this.personBindingSource.DataSource = this.dsWBGT;
}
and finally my event looks like this:
private void dgvUsers_CellContentDoubleClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex == 1)
{
Forms.Person.frmPerson personForm = new WBGT.Client.Forms.Person.frmPerson();
personForm.UserId = (Guid)dgvUsers.Rows[e.RowIndex].Cells[0].FormattedValue;
THIS IS WHERE IT FAILS :((
personForm.GetPersonByUserId();
personForm.MdiParent = frmMain.ActiveForm;
personForm.Show();
personForm.BringToFront();
}
}
Thank you!
Illegal Operation
|
|
|
|
|
Wouldn't a FormattedValue be a string? Not a GUID?
|
|
|
|
|
Not to worry, I have fixed it.
I Converted the Guid to a String and then Passed the string to the property, worked like a charm.
Thank you!
Illegal Operation
|
|
|
|
|
Taking a value, making it a string, then parsing it back to the value it was is wasteful and considered to be poor coding practice.
|
|
|
|
|
Does anyone know how to copy a transparent image out of a C# application into the clipboard, and then paste it into Photoshop? When I try this the transparency (alpha) is lost. Here's as far as I got, but it doesn't work (transparency is still lost):
IDataObject dataObject = new DataObject();
dataObject.SetData(bMap);
MemoryStream ms = new MemoryStream();
bMap.Save(ms, ImageFormat.Png);
dataObject.SetData("PNG", false, ms);
Clipboard.SetDataObject(dataObject, true);
|
|
|
|
|
See if this[^] helps.
Or maybe this[^] one. You'll have to read through the replies, to find one that works for you, I hope!
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
Thank you very much for the links! I had been working on this problem all day and had came across them. The code snippet I posted was actually based on the second thread. The code snippet adds a PNG to the clipboard which allows transparent images to be posted to Excel. Unfortunately Photoshop, as well as most programs, don't seem to look for PNGs on the clipboard so it didn't help specifically with Photoshop.
|
|
|
|
|
Oh well.
Hope you find a solution.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|
I want to know which one is bets to use with Windows Form? Crystal Reports or RDLC? and why plz?
|
|
|
|
|
|
hey , i am new to c# , with a bit of experience and i am wondering how i would go about making a back up program, such as syncing one folder with another.... For example; copying new data in folder 1 to folder 2 ... how would i go about making this ? and if you could direct me to a useful tutorial or tell me some of the code i would be very happy thanks !!!
|
|
|
|
|
No one will really give you such code, because it is readily available by using Google, or reading a book for beginnings. This is basic functions that are taught at a very early level, when you said a bit of experience I assume you where overstating, to say the least.
Please Google for introductory articles on C# and .Net, make use of MSDN (as the examples posted are extremely helpful to beginners and professionals alike) and become accustomed to researching first, trying second and then asking for help, but on specific areas where you get stuck. Not an entire project.
|
|
|
|
|
sorry, i did search , just didn't know what to look for , hence why i was asking for advice and support ... thanks anyway
|
|
|
|
|
Regardless, your initial post still asked for code, which is generally frowned upon around here. You will see people here willing to help you a great deal if your question revolves around a specific bug and you've sincerely tried to accomplish something, anything other then coming here first.
Good luck with your work.
|
|
|
|
|
Well obviously i am new around here and didn't know what to put so i generally asked for code , regradless or not of peoples feelings to the topic of asking for source code , the term code could of meant that you can give me an example or you can tell me what type of code is required for me to research to reach my goal, i am very sorry , i have learnt my lesson to not use the term "code" in general circumstances , thank you
|
|
|
|
|
weirdsteve wrote: just didn't know what to look for
Let me help[^]
only two letters away from being an asset
|
|
|
|
|
Thank you very much for your help Mark Nischalke ! at least there are some kind people on here who will just even quote or tell me what i am suppose to search Thank you ...
|
|
|
|
|
weirdsteve wrote: at least there are some kind people on here who will just even quote or tell me what i am suppose to search
The title of your thread is "C# back up program"
Google for your own title and you would get
Backup Utility in C#[^]
as the second hit (the first is your thread)
So.. you're basically learning how to use Google. Good for you.
|
|
|
|
|
erm thanks for that ..... all you people are not nice are you :S okay sorry , and i know google is quite good isn't it ? i mean you can search anything , i did actually try that result obviously and i couldn't open the .zip file on visual basic 2008 as it wasn't compatible , hence why i thought i could come here for a bit of help as i thought you were kind people and would lend a hand instead of giving a person a hard time .... but yeah google is good as you can search a word in the text box WOW !
|
|
|
|
|
weirdsteve wrote: i did actually try that result obviously and i couldn't open the .zip file on visual basic 2008 as it wasn't compatible
Then you're also in the wrong forum, batting 100% aren't we today?
|
|
|
|
|
battling ? who said i was ? i am just saying my opinion on the subject ... and no i am in the right forum .. and can't help it for visual basic c# express 2008 faults which stop me from learning ... if u are battling ... may i suggest you stop as i am just saying my opinion and only asked for a bit of help on a forum i don't know but read the terms of use and how to question ...... But may i suggest you look at how to answer a question which is
HERE![^]
and i can seriously say that the question was not in the wrong forum, not inappropriate, in perfect English but could of been poorly structured for you to understand .. so read carefully. ..
|
|
|
|
|
Batting, not battling, you must learn to read my posts, it's an expression about baseball that is combined with sarcasm to illustrate the amount of mistakes you've made in a short period of time.
Here[^] is a guide about asking a question.
|
|
|
|
|
And sarcasm , like everyone knows, doesn't work on text typed on a forum or document with nothing to suggest it is in fact how u are saying it , all i needed was nice simple help.. which would be better with a simple answer, such as .... " weirdsteve the thing you need to research on google is "c# file copying" which will direct you to the right source for your problem"
|
|
|
|