General discussion

Locked

All Things .NET

By BenHinton ·
Tags: Off Topic
blog root

This conversation is currently closed to new comments.

12 total posts (Page 1 of 2)   01 | 02   Next
| Thread display: Collapse - | Expand +

All Comments

Collapse -

Enterprise Library for .NET v2.0

by BenHinton In reply to All Things .NET

<p>Over the last year or so Microsoft have been steadily releasing updates for the Enterprise Library. In case anyone doesn't know what this, have a look at the <a href="http://msdn.microsoft.com/practices/guidetype/appblocks/default.aspx?pull=/library/en-us/dnpag2/html/entlib.asp">Patterns msdn site</a> . Basically it's a collection of classes that provide a wealth of reusable functionality for <em>Data</em>, <em>Caching</em>, <em>Security</em>, <em>Configuration</em>, <em>Logging</em> etc etc. If you haven't used it up until now, I would deifinitely recommend it!</p>
<p>Anyway, anyone who has been using the Microsoft Enterprise Library for .NET v1.1 and is keen on switching over to the new version of .NET (v2.0 aka VS.NET 2005) will be interested to hear that there is a prerelease of the <em>new</em> version of the Enterprise Library available on gotdotnet. It can be downloaded <a href="http://www.gotdotnet.com/codegallery/codegallery.aspx?id=295a464a-6072-4e25-94e2-91be63527327">here</a>.</p>

Collapse -

Internet Explorer ActiveX

by BenHinton In reply to All Things .NET

<p>Most of the time I get on pretty well with Microsoft products and in general things tend to stay fairly stable. However, a few weeks ago for some reason unknown to me Internet Explorer decided that it didn't want to run any ActiveX controls any more. This meant that any site that uses Flash doesn't work; and site that requires any kind of plugin doesn't work; and of course, Windows Update doesn't work.</p>
<p>The crux of it is that ActiveX is completely disabled. The information bar that is meant to appear has completely vanished. All the information I have found on this problem just simply states resetting the Security settings in Internet Options, but it makes no difference whatsoever.</p>
<p>I thought I would try and download the beta version of Internet Explorer 7 from MSDN, but unfortunately the Microsoft File Transfer program that manages the download from MSDN requires... you guessed it, and ActiveX control to be installed. So, can't do that either.</p>
<p>It seems the only answer is a complete re-install of Windows XP. Drastic, I know - but there really seems to be no other way. So, as usual, when you have a problem with Windows it comes do to the only 2 answers; re-boot and if that doesn't work, re-install.</p>
<p>As always if anyone has any suggestions please let me know.</p>

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by BenHinton In reply to All Things .NET

A week or two ago I spent hours and hours trying to get what I thought would be such a simple thing working. All I wanted to do was have two <font face="Courier New">RichTextBox</font> controls on a <font face="Courier New">Form</font> and have the scrolling of them both syncronized. Doesn't sound too hard does it?
<p>However, I very quickly discovered that with .NET v1.1 <font face="Courier New">RichTextBox</font> controls do not expose any events or properties that allow you to manipulate the built in scrollbars programatically. Stupid of me to even think that they would really! So, then I thought that perhaps I could add my own scrollbars to the RichTextBox control using the <font face="Courier New">HScrollBar</font> and <font face="Courier New">VScrollBar</font> controls. Wrong again
<p>So, then I turned to the Internet and to your friend and mine; <i>Google</i> (oh, and MSDN) which came back with a few helpful tips on using API calls to do the job. It wasn't ideal but it looked like it would work. The general principal was to create a new control that is derived from <font face="Courier New">RichTextBox</font>. In this new control the idea is fairly straightforward...
<p>...first you override the <font face="Courier New">WinProc</font> method so we can catch the <font face="Courier New">WM_VSCROLL</font> and <font face="Courier New">WM_HSCROLL</font> messages. Then you create a <font face="Courier New">delegate</font> that can be called to set the scroll position of the other <font face="Courier New">RichTextBox</font> control based on the location of the scrollbar in the current <font face="Courier New">RichTextBox</font> control.
<p>The API calls in question are: <font face="Courier New">SetScrollPos, GetScrollPos, GetScrollInfo, SetScrollInfo</font> and <font face="Courier New">ScrollWindowEx</font>.
<p>But could I get it to work properly? No. I could get the scroll bars moving but the contents would not refresh properly.
<p>After some more intense searching though I stumbled upon an excellent article on <font face="Courier New"><a href="http://www.codeproject.com/vb/net/RTFSynchronizedScrolling.asp">thecodeproject</a></font> that had an implementation specifically for <font face="Courier New">RichTextBox</font> controls. It's a custom class with a <font face="Courier New">NativeWindow</font> whereby you add as many <font face="Courier New">RichTextBox</font> controls to it and it captures the scroll messages and syncronizes all the other controls. Worked like a charm! I also converted it from VB.NET to C# as the rest of my project was in C#. Basically it all works with one API call:
<p><font face="Courier new" size="2">[DllImport("user32.dll", EntryPoint="SendMessage"]<br /><font color="blue">private static extern int</font> SendScrollPosMessage(IntPtr hWnd, <font color="blue">int</font> Msg, IntPtr wParam, <font color="blue">ref</font> Point lParam);</font>
<p>Nice!
<p>Can't add attachments on here but if you want the code, let me know. </p>

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by joshley2 In reply to C# Synchronised Scrolling ...

<p>I would love the C# code for this!!</p>
<p>If you could email it to:<br /><a href="mailto:joshley2@hotmail.com">joshley2@hotmail.com</a></p>
<p>Then I would be incredibly appreciative!</p>
<p>Thanks very much,<br />Josh</p>

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by thecody In reply to C# Synchronised Scrolling ...

ditto... code would be immensely useful to me as well...<br />
<br />
send to: richtext@tk23.com<br />
<br />
thx.<br />

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by monique_s80 In reply to C# Synchronised Scrolling ...

<p>This is exactly that I was looking for today. Could you please, please e-mail me the code?</p>
<p><a href="mailto:monique_s80@hotmail.com">monique_s80@hotmail.com</a></p>
<p>THANK YOU IN ADVANCE!</p>
<p>Bye bye.</p>
<p>Monique</p>

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by coleydog In reply to C# Synchronised Scrolling ...

<p>What's wrong with</p>
<p(Control) richTextBox).Select(); // use the base control's Select method.</p>
<p>richTextBox.SelectionIndex = richTextBox.Text.Length // scrolls to the bottom of the control</p>
<p>Any other value of SelectionIndex will scroll to the appropriate position and with multiple synchronized rtb's will scroll correctly regardless of their rtb's sizes.</p>
<p> </p>

Collapse -

C# Synchronised Scrolling RichTextBox Controls

by BenHinton In reply to C# Synchronised Scrolling ...

<p>Monique,</p>
<p>Have you actually had that working so that multiple rtb controls are all syncronizing, both vertically and horizontally? I have never managed to get it working apart from the technique used in the code I send you (in the blog). I would be interested to see the code you have used to make it work another way...</p>
<p>Ben</p>

Collapse -

The Case for Nullable Types

by BenHinton In reply to All Things .NET

<p>For a while now I've been using some custom Nullable types with .NET 1.1 (located <a href="http://nullabletypes.sourceforge.net">here</a&gt. Nullable types have now been introduced to the new version of .NET (2.0), and I quite like the way that Microsoft has implemented them.</p>
<p>The issue with nulls up until now are that value types such as <font face="Courier new">int</font>, <font face="Courier new">long</font> and <font face="Courier new">bool</font> cannot hold a <font face="Courier new">null</font> value. This is simply because only reference types can be <font face="Courier new">null</font>. Even though .NET gives you automatic boxing and unboxing of value types this still doesn't allow you to assign a <font face="Courier new">null</font> value to it.</p>
<p>So, whats the problem anyway? Well, consider a database application. A table in a database can define a column of type <font face="Courier New">int</font>, which as far as the database is concerned can either hold an <font face="Courier New">int</font> value or can just be <font face="Courier New">null</font>. So if the value in the database <i>is</i> <font face="Courier New">null</font> how do you reflect this in your class if you can't assign <font face="Courier new">null</font> to an <font face="Courier new">int</font>? Consider also a <font face="Courier new">bool</font> type. You may have a column in the database of type <font face="Courier New">char</font> (or <font face="Courier New">int</font>, again) and you need to know if its value represents true, false or unspecified. So, a <font face="Courier New">null</font> value can actually be very useful as a tri-state boolean.</p>
<p>Now, in the following line of code that uses a standard <font face="Courier new">bool</font> type, if the value of the column <font face="Courier New">MobilePhone</font> is <font face="Courier New">null</font> you will get an exception at runtime:</p>
<p><font face="Courier new"><font face="Courier new" color="blue">bool</font> hasMobilePhone = reader.GetBoolean(mobileOrdinal);</font></p>
<p>This is because the reader has returned <font face="Courier New">null</font> and you can't assign it to the value type. So you would have to do something ugly like:</p>
<p><font face="Courier New"><font face="Courier new" color="blue">bool</font> hasMobilePhone = <font face="Courier new" color="blue">false</font>;<br /><font face="Courier new" color="blue">if</font> (!reader.IsDBNull(mobileOrdinal))<br />    hasMobilePhone = reader.GetBoolean(mobileOrdinal);</font><br />    <br />Not very nice at all! And not only that but if the value <i>was</i> null then the <font face="Courier New">hasMobilePhone</font> variable will contain false which is not representative of the data!</p>
<p>By using nullable types in C# 2.0 you could just do this:</p>
<p><font face="Courier New"><font face="Courier New">bool</font>? hasMobilePhone = reader.GetBoolean(mobileOrdinal);</font></p>
<p>The expression <font face="Courier New">bool?</font> declared a value type of bool that can now contain <font face="Courier New">null</font>. You will notice some additional properties on the variable as well. The <font face="Courier New">Value</font> property will give you the underlying value type and <font face="Courier New">HasValue()</font> can be used to query the type and see if there is a value or not. You might wonder why these are needed at all! The answer is that you may rely on this value and you only want to do something if the value is <strong>not</strong> <font face="Courier New">null</font>. This is achievable because if you use the <font face="Courier New">Value</font> property and the value <i>is</i> actually <font face="Courier New">null</font>, an exception will be thrown - thus not allowing you to use it. This is correct behaviour because if you called <font face="Courier New">Value</font> on a nullable type where the value was in fact <font face="Courier New">null</font> and you were returned zero instead then once again this would not reflecting the correct value of the data.</p>
<p>There is also a neater way of testing the nullable type using the new expression <font face="Courier New">??</font>.</p>
<p><font face="Courier New"><font face="Courier new" color="blue">bool</font>? hasMobilePhone = <font face="Courier new" color="blue">null</font>;</p>
<p><font face="Courier new" color="green">// Do some processing</font><br />...</p>
<p><font face="Courier new" color="green">// Output some text</font><br /><font face="Courier new" color="blue">string</font> output = <font face="Courier new" color="blue">string</font>.Format("Mr Big has a mobile? '{0}'", hasMobilePhone ?? "Unspecified");</font></p>
<p>This expression basically means, if <font face="Courier New">hasMobilePhone</font> is actually <font face="Courier New">null</font>, use <font face="Courier New">"Unspecified"</font> instead. If you didn't do this and the variable was <font face="Courier New">null</font> an exception will be thrown.</p>
<p>All in all, I think they're really useful.</p>

Collapse -

Installing and Using Team Foundation Server Beta 3

by BenHinton In reply to All Things .NET

<p>Well after many hours and three attempts at re-installation I have finally got Team Foundation Server Beta 3 working. I can't say for sure exactly what the problems were but they seemed to be related to permissions with the user accounts you need to create. </p>
<p>It's a complex install because you have to install IIS, SQL Server 2005 and SharePoint Services. The difficulty is that there are little snippets that you have to consider which can easily be missed. For example, with IIS you <em>must not</em> install the Front Page Server extentions. With SQL Server you <em>must</em> install with the default server instance (MSSQLSERVER). If you choose your own instance name, then it won't work - a most ridiculous constraint if you ask me! Then there is SharePoint Services... don't touch the configuration page that comes up at the end of the install or you'll open up a can of worms.</p>
<p>Even following the installation instructions to the letter didn't give me a fully working instance. The first time I installed I was getting errors during the installation that SQL Analysis Services couldn't be accessed as well as a strange error with an Event service (which I think was to do with reporting services permissions). The second time it installed ok but when trying to create a new Team Server project in Visual Studio 2005 it would throw and error. This is not unexpected behavior with a Beta product but the annoying thing was that it didn't roll back the changes so I was left with 3 source control projects that I couldn't do anything with and also couldn't delete!</p>
<p>The final installation worked and also created the VS.NET 2005 projects. Then I browsed to the project portal page for my new project... unfortunately the panes that show the build status' etc just showed errors! As you can imagine I was utterly disappointed that after all this time I still hadn't got a fully working installation. So, this time, rather than complete reinstall I decided that I would try the 'Repair' option on the Team Foundation Server setup. And guess what? It all worked!!</p>
<p>So, I've been using VS.NET 2005 with Team Foundation Server Beta 3 for a few days and it's been going really well. Well, that was until this morning when I opened up my laptop on the train. You see, I was expecting the Visual Studio solution to tell me that I wasn't connected to the server and offer me the opportunity to <em>work offline</em>. However, this was too much to ask for. Instead, it told me that it could not connect and then gave me the option of temporarily working without source control or removing the binding completely!</p>
<p>When I got to work, I went to google to see what I could find about setting up Team Foundation Server/VS.NET 2005 for working offline - and do you know what the answer is?? You have two options. <em>1)</em> Check out the files you want to work on <em><strong>before </strong></em>you disconnect from the internet (which means you have to actually know all the files you plan to work on before you disconnect - highly unlikely!!!), or <em>2)</em> Manually unselect the 'readonly' attribute on each file that you want to work on. With both options you checkout/check in each file accordingly when you reconnect! I was totally dumbfounded that with this product - which is designed for remote working (so Microsoft say) you cannot easily work offline. See the transcript from this interview on MSDN <a href="http://msdn.microsoft.com/chats/transcripts/vstudio/05_0511_dn_vstf1.aspx">here</a>.</p>
<p>Hopefully the next Beta/technology preview will be released and will fix some of these bugs/features.</p>

Back to After Hours Forum
12 total posts (Page 1 of 2)   01 | 02   Next

Related Discussions

Related Forums