|
Wayne Gaylard wrote: whereas in an explicit implementation, the method must be declared as private, meaning that the method can only be accessed by an instance of the Interface.
A ha! I wondered why the IDE didn't put "public" in front of my methods when I chose to explicitly implement from the shortcut menu.
Thanks for the terrific post.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
No worries - glad I could help.
When I was a coder, we worked on algorithms. Today, we memorize APIs for countless libraries — those libraries have the algorithms - Eric Allman
|
|
|
|
|
These MSDN sources have been helpful to me in my research on interfaces:
HopCroft's overview:[^]
Brad Abrams ideas about when to use explicit vs. implicit interfaces I find very helpful:[^]
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
In general I'd only ever do this if there is a name clash with a method from another interface or which already exists in the class hierarchy. The commonest case is implementing IEnumerable<T>, when you need to provide two GetEnumerator methods.
However, the linked article from the answer above mine raises an interesting point: if the interface is only implemented for infrastructure reasons and you never expect an 'end user' developer to actually call the methods on your class manually, it might make sense to explicitly implement them. So one might argue that both GetEnumerators should be explicitly implemented, as they're there for infrastructure reasons (being able to enumerate over the class) and not to be called directly.
For a custom interface that would be true if it is something which has special meaning for a framework you have created, so all a class needs to do from an external point of view is implement it and some clever stuff happens. For example let's imagine a slightly cleverer version of my socket library which specified an interface thus:
public interface ITransferrable {
byte[] GetBytes();
void Restore(byte[] bytes);
}
... and some magic which I won't go into (restoring would be slightly non-trivial and writing that out wouldn't help the point) which allowed you to send and retrieve ITransferrables through the normal send/receive mechanism.
Apart from code inside Sockets.cs, no-one would ever explicitly call those two methods. So, even without a name clash, it might well make sense to explicitly implement that interface, because you don't need to see them when you are inspecting the implementing class in a domain context.
|
|
|
|
|
How do you handle this?
Girl girl = new Girl(Type.LovelyOne|Type.KindOne|PrettyOne);
Boy you = new Boy(Type.KindOne|Type.Married);
girl.Love(you);
girl.MakeLove(you);
you.IsInLove = true;
girl.ReturnedToHerBoyfriend = true;
girl.Leave();
you.Dispose();
Fatal Error!
Sojaner!
|
|
|
|
|
Does anyone know the incantation to save an excel workbook without having the "Do you want to save" popup appearing? I cannot have the confirmation appear because the alterations I am making to the file need to be seamless.
Application excel = new Application();
Workbook workbook = excel.Workbooks.Open(Filename);
var sheet = workbook.ActiveSheet;
Range column = sheet.Range["B1"].EntireColumn;
column.Insert(XlInsertShiftDirection.xlShiftToRight);
workbook.Save();
workbook.Close();
Marshal.ReleaseComObject(workbook);
Marshal.ReleaseComObject(excel);
This will save the file, but the popup is not suppressed.
"I need build Skynet. Plz send code"
|
|
|
|
|
|
Thanks, Mark.
"I need build Skynet. Plz send code"
|
|
|
|
|
Hurray! I get to answer my own question lol
excel.DisplayAlerts = false;
fixed.
"I need build Skynet. Plz send code"
|
|
|
|
|
Can anyone point me to somewhere or suggestion on how to get the zoom window box that I can attach to the mouse when the mouse hovers over a control, such as a custom-control. the text may be too small to read but with this zoom feature, would bring up a closer look of that control.
thanks!
|
|
|
|
|
I have multiple RichTextBox controls which are set up as "pages" in a document. The size of each RTB is fixed. How can I tell, when the user types or presses ENTER or anything, if the input must move to a new page? The RTBs can of course have various formatting, font sizes, etc. I cannot figure it out. Perhaps I looked over it in a Google search but I could not find anything similar no matter where I looked. It has been puzzling me for a few days now. Hehe.
Thanks in advance!
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
didn't vote you down, but my guess is the person in question did so because your question wasn't really clear. What do you mean with pages? What is the exact problem and what did you do to try to solve it? What do you mean with fixed size? etc...
Remember, we're not working on your project and don't have a clue about your terminology to start with.
V.
|
|
|
|
|
Wow. I guess I should not ask questions when I am terribly sleep deprived. Anyhow, I should clarify the question now.
I have a panel which contains "pages". Each page is a RichTextBox control which I create at a specific size. I set the size at 8.5 * DpiX by 11 * DpiY, which, from what I read, is like 8.5" x 11" on the screen. This size is fixed, meaning the size of the RTB will never change.
The functionality I wish to achieve is similar to that of Microsoft Word, in which the user types on a page (RTB control). And once the text reaches the bottom of the RTB's bounds, I would like to move the "offending" text (the text which does not fit in that particular RTB) to a new page/RTB, which is placed below the original page. I have already implemented inserting pages and such, by adding a new RTB control to the container panel. This works as expected.
I have done some more digging and I found the RTB event called "ContentsResized". MSDN says "Occurs when contents within the control are resized." After playing with this event I have discovered that I can detect when the last line goes beyond the RTB's height. Here is what I have:
MuRichTextBox page = (MuRichTextBox)sender;
int topMargin = (int)(page.TopTextMargin * DpiY);
int bottomMargin = (int)(page.BottomTextMargin * DpiY);
if (page.Lines.Length > 0 && e.NewRectangle.Height > (page.Height - (topMargin + bottomMargin)))
{
if (page == this._pages[this._pages.Count - 1])
this.InsertPage();
}
DpiY is retrieved from:
Graphics g = page.CreateGraphics();
float DpiY = g.DpiY;
When I use this a new page is inserted. But I am not sure how to move the "offending" line from the first page to the newly inserted page. Is that more clear?
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Just saw I never replied on this (apologies for that). Do you still need help on this?
Looks rather complex. The only thing I can think of, is trying to measure the size of the string. I remember that GDI+ could do this based on the string and the font (size, type, etc...). it's hell to find the conversions between points/pixels and actual size in mm, cm, m though.
V.
|
|
|
|
|
I have been following your series of questions and I wonder if it wouldn't be easier to manage the content and the pagination yourself, with a completely custom control. The RichTextBox isn't that great in the first place, and you're having to do quite a lot of hackery to adjust it for your needs. Measuring, rendering and editing simple text with inline formatting markup is not particularly hard, and if you want to go beyond that (tables, inline images, floating wraparounds etc) the RichTextBox tends to mess them up anyway.
|
|
|
|
|
Oh, interesting. Thank you for the insight, BobJanova. I will definitely take that into consideration. Currently I am learning how to develop custom controls by extending existing controls. Once I am more comfortable with the whole concept I will likely follow your advice. Do you have any resources in mind at the moment which I could read to learn more about what you are suggesting? I will be doing some research of my own. But any help in the proper direction is appreciated.
Does MS Word likely use something OTHER THAN the RTB? I am not trying to create something that will "rival" Word by any means, I am just trying to achieve some of the fairly basic functionality.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Matt U. wrote: Does MS Word likely use something OTHER THAN the RTB?
It certainly does. I'm not sure how true this still is, but up to a couple of versions ago, the Word edit page was actually written in a mix of C and assembly to get the maximum speed possible.
|
|
|
|
|
Wow. I never would have guess (obviously), haha. Thanks, Pete. I am currently reading up on rendering my own text and such. Thanks again.
djj55: Nice but may have a permission problem
Pete O'Hanlon: He has my permission to run it.
|
|
|
|
|
Yes, Word definitely custom renders.
You can find a section about how to develop custom controls from UserControl (in WinForms) in my LineEditor article[^].
I would also recommend reading up on how TeX lays out content if you want to go for anything more complicated than a single text stream.
As a bonus, once you have a layout engine that will work for your custom control, it should be trivial to switch the renderer from painting onto a control to using a printer or creating a fixed output format like EPS or PDF.
|
|
|
|
|
Assuming you are using a RichTextBox with vertical scrolling turned off, you can detect when entered content exceeds the height of the RTFBox via the ContentsResized Event:
private void richTextBox1_ContentsResized(object sender, ContentsResizedEventArgs e)
{
if (e.NewRectangle.Height > richTextBox1.Height)
{
textBox1.Text = e.NewRectangle.ToString();
}
} Whether you could adapt this to meet your needs: I don't know.
best, Bill
"I have always wished for my computer to be as easy to use as my telephone; my wish has come true because I can no longer figure out how to use my telephone." Bjarne Stroustrop circa 1990
|
|
|
|
|
Hello everybody. For *two weeks*, each day since I installed Windows 7, I have been struggling to get something to work. Something which worked perfectly ok in XP. It's driving me mad, poisoning my life, ruining my days. Why such a simple task works SO CHAOTICALLY!?
I think I discovered a bug in Windows 7, specifically in the way the ShowWindow function works in the standard theme (Aero).
To demonstrate this, I uploaded 2 C# WinForms applications and their source code.
http://www.axonnsd.org/W/P007/BugsDemo.rar
HideableApplication represents an application which you can hide in the SysTray when you close it. Double clicking the SysTray icon reveals it and right clicking will reveal the "Exit" option.
HideableApplicationRevealer attempts to show HideableApplication's window.
The reason I need to accomplish this task is because I minimize my Total Commander and FireFox to the Tray and I want to bring them back via a HotKey. Total Commander offers such a functionality but it is broken.
On Windows XP I managed to accomplish both these tasks without any problems, using the code I attached.
On Windows 7, the behavior is erratic at best, and non-functional at worst.
When HideableApplication runs inside Visual Studio everything works:
- Trying to reveal it via HideableApplicationRevealer from Visual Studio => SUCCESS
- Trying to reveal it via manual execution of HidebleApplicationRevealer.exe from Debug folder => SUCCESS
- Trying to reveal it via running HideableApplicationRevealer.exe via keyboard shortcut => SUCCESS
- Trying to reveal it via running HIdeableApplicationRevealer.exe via a Scheduled Task with Admin Rights => SUCCESS.
When HideableApplication was executed manually (via .exe from Debug folder) AND Visual Studio IS STARTED, it works if I use admin rights or run it manually:
- Trying to reveal it via HideableApplicationRevealer from Visual Studio => FAIL
- Trying to reveal it via manual execution of HidebleApplicationRevealer.exe from Debug folder => SUCCESS
- Trying to reveal it via running HideableApplicationRevealer.exe via keyboard shortcut => FAIL
- Trying to reveal it via running HIdeableApplicationRevealer.exe via a Scheduled Task with Admin Rights => SUCCESS.
- Trying to reveal it via running HideableApplicationRevealer.exe via keyboard shortcut (start menu) which has been given ADMIN RIGHTS => SUCCESS.
When HideableApplication was executed manually (via .exe from Debug folder) AND Visual Studio HAS BEEN SHUT DOWN: it only works if I run it manually (double click exe):
- Trying to reveal it via manual execution of HidebleApplicationRevealer.exe from Debug folder => SUCCESS
- Trying to reveal it via running HideableApplicationRevealer.exe via keyboard shortcut => FAIL
- Trying to reveal it via running HIdeableApplicationRevealer.exe via a Scheduled Task with Admin Rights => PROBLEMS: Window blinks on the TaskBar instead of being shown!
- Trying to reveal it via running HideableApplicationRevealer.exe via keyboard shortcut (start menu) which has been given ADMIN RIGHTS => SUCCESS.
If it matters, I reproduced this behavior both with the Taskbar in its standard position AND also with it set to AutoHide, in the left of the screen.
Apparently, I need admin rights to show a window, but even like this, it doesn't work right when I use the Scheduled Task workaround (create Scheduled Task with admin rights and invoke the Scheduled Task via system32/schtasks.exe /run /tn "task name"). What happens is that AFTER VISUAL STUDIO IS SHUT DOWN, the window blinks on the TaskBar instead of being shown (and has no focus). It does appear, but it has no keyboard focus, which should NOT happen because I also used the SetForegroundWindow API.
This is exactly what happens when I try to run reveal Total Commander as well: read below, same behavior: blinks on taskbar instead of being shown.
And don't even get me started on the difference in behaviors between when running it from Visual Studio and when running it from its usual C:\MyProjects folder.
My TotalCommanderRevealer and FireFoxRevealer exhibit even stranger behaviors: when starting Visual Studio, the Total Commander app stops working properly. Even if I load NO PROJECT, instead of showing TC to me, it just blinks it on the TaskBar. However if I open the TCRevealer project, it starts working again! If I shut down Visual Studio, it STOPS working UNTIL I RESTART WINDOWS.
The FireFoxRevealer instead of revealing FireFox, does something very strange: it shows a small label in the top-left corner of the screen, usually with something related to the opened tab. I suspect this has to do with the Window Style and the way the ShowWindow function works in Windows 7. However, sometimes it works, showing the actual window. But most of the time it doesn't. And when it stops working, I never get it to work again until certain unknown circumstances occur and it works again. Regardless, this worked pefectly under Windows XP and does not work at all now.
If you wish to reproduce the FireFox issue, use the code I attached: instead of searching for "Hideable Application" text in FindWindow API, search for "MozillaWindowClass", install FireFox 7 or 8 and install the FireFox "Minimize To Tray Revived" addon.
I should also mention that I'm aware of the "ForegroundLockTimeout" registry setting and I have set it to 0 everywhere it appears in the Registry. On Windows XP it is set by default to 0 but in Windows 7 the default value was 200000, which I have changed. Maybe somehow it lingers somewhere??? And Visual Studio, while running, sets it to 200000 when I shut it down, until I restart the computer? I looked in the Registry and it doesn't change, it's still 0. But who knows?
|
|
|
|
|
I am sending image path(as image save in folder) from web service like
[System.Web.Services.WebMethod(), System.Web.Script.Services.ScriptMethodAttribute()]
public static string GetDynamicContent(string contextKey)
{
string constr = "Data Source=Subhasish-PC;Initial Catalog=testabhijit;Integrated Security=SSPI;";
string query = "SELECT ImagePath FROM imagetable WHERE id = " + contextKey;
SqlDataAdapter da = new SqlDataAdapter(query, constr);
DataTable table = new DataTable();
da.Fill(table);
string x = table.Rows[0]["ImagePath"].ToString();
return x.ToString();
}
Now at .aspx page i am taking panel and image control, like below
<asp:Panel runat="server" CssClass="modalPopup" ID="panSaving" Style="display: none">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td>
<asp:Image ID="imgClose" runat="server" ImageUrl='' Height="336" Width="430"/>
</td>
</tr>
</table>
</asp:Panel>
My problem is how i will bind ImageUrl of image control......so that which path is sending at web service i can access. Thank you.
|
|
|
|
|
Let us assume a client-server application. The server communicates with a database, which contains a table with users. That table stores the passwords.
Of course, passwords are not stored in clear text. In version 1, MD5 was used.
With version 2, that was changed to SHA-1.
Now a customer with more than a hundred users wants to update from version 1 to version 2.
And suddenly you see a problem: You cannot migrate the passwords because there is no function for calculating the SHA-1 value for a given MD5 value - you need the passwords in clear text which is not available.
How would you handle/avoid such a situation?
|
|
|
|
|
In the new password file, put a header on each record to indicate the hash used, for example
MD5.Fred Smith.qwertukljndfvoijer4tgp[oidjfbvdfv
MD5.Joe Bloggs.lkjrfsgbdqkdfvlkdfv456cxvfth
SHA1Alan Black.345908udfvdf340fgkldrsdfsdfsgb
This allows for graceful migration as passwords are renewed/reissued/whatever.
No claims for originality, but I know this technique works.
Cheers,
Peter
Software rusts. Simon Stephenson, ca 1994.
|
|
|
|
|
Gets my five - the only sensible way to handle it.
Ideological Purity is no substitute for being able to stick your thumb down a pipe to stop the water
|
|
|
|
|