Regarding bullets and levelled bullets in ms word using c# - c#-4.0

I have a ribbon button which inserts numbered bullets in my doc like so:
private void button4_Click_1(object sender, RibbonControlEventArgs e)
{
Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery];
oPara = oDoc.Content.Paragraphs.Add(range);
listFormat = oPara.Range.ListFormat;
this.ApplyListTemplate1(listGallery, listFormat, 1);
range.ListFormat.ListLevelNumber = 1;
}
and I have another button which applies levelled numbered bullets like 1.1 ,1.2 etc like this
private void button5_Click(object sender, RibbonControlEventArgs e)
{
Word.ListGallery listGallery = Globals.ThisAddIn.Application.ActiveDocument.Application.ListGalleries[Word.WdListGalleryType.wdOutlineNumberGallery];
oPara = oDoc.Content.Paragraphs.Add(range);
listFormat = oPara.Range.ListFormat;
this.ApplyListTemplate1(listGallery, listFormat, 2);
oPara.Range.ListFormat.ListLevelNumber = 2;
}
Here is my apply list template:
private void ApplyListTemplate1(Word.ListGallery listGallery, Word.ListFormat listFormat, int level = 2)
{
listFormat.ApplyListTemplateWithLevel(
listGallery.ListTemplates[level],
ContinuePreviousList: true,
ApplyTo: Word.WdListApplyTo.wdListApplyToSelection,
DefaultListBehavior: Word.WdDefaultListBehavior.wdWord10ListBehavior,
ApplyLevel: level);
}
The problem:
Here if I click on the level 1 button it inserts a numbered bullet , like "1." and I click on second button, it inserts "1.1.", and now if I press the first button to insert "2 ." it inserts fine, but the second button click does not insert 2.1 ,instead it inserts "1.2" Have been stuck on it for days.

Instead of using
oPara.Range.ListFormat.ListLevelNumber = 2;
I used oPara.Range.ListFormat.ListIndent();
and oPara.Range.ListFormat.Outdent() instead of oPara.Range.ListFormat.ListLevelNumber = 1;
and it worked without bugs.

Related

Is it possible to show context menu for range of items selection in datagridview using C#

Is it possible to show context menu for range of items selection in datagridview using c#. In general we can show context menu when select any item and right-click on mouse.
Similarly can we show same context menu for range of items (two or more items selection) in datagridview in windows application?
Thanks.
Here's what I do. Assuming your DataGridView(DGv) is dataGridView1 and ContextMenuStrip is cms
First set MultiSelect & SelectionMode property of the DGv to true & FullRowSelect respectively.
//capturing current mouse coordinate to diplay menu where the mouse pointer is.
//MouseX & MouseY is an int variable and it's global to this class.
private void dataGridView1_MouseDown(object sender, MouseEventArgs e){
MouseX = e.X;
MouseY = e.Y;
}
//Avoid row selection when Right Click. This is optional you can ignore this one if you want to select the Row on Right Click
private void dataGridView1_MouseUp(object sender, MouseEventArgs e){
if (e.Button == MouseButtons.Right){
DataGridView.HitTestInfo hti = dataGridView1.HitTest(e.X, e.Y);
dataGridView1.Rows[hti.RowIndex].Selected = false;
}
}
//Time to show the menu.
private void dataGridView2_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e){
if(e.Button == MouseButtons.Right && e.RowIndex > -1){
contextMenuStrip1.Items.Clear(); //Since I am adding the menu items dynamically. I am clearing the previous menu to avoid repeatition. Ignore this step if your menu is static/predefined
foreach(DataGridViewRow gr in dataGridView1.Rows){
if(gr.Selected){
//if row is selected, I adding the Value of the First Cell as Menu Item
cms.Items.Add(gr.Cells[0].Value.ToString());
cms.Items.Add("-"); //adding menu separator
}
}
cms.Show(dataGridView1, new System.Drawing.Point(MouseX, MouseY)); //this will add First Cell Value of all selected Rows as menu item and display the Context Menu
}
}
I hope this suffice your requirement.

UWP - How to create a TokenAutoComplete Control

I am developing UWP (Win10 - VS2015) App. I need a Token TextBox in Windows Platform. Any idea please, how to start and create this control, then when writing text inside the Textbox and put space or just tap that text, it should convert into selected Token. See the pic (its just for idea). I need such type of control.
You can also get idea from this Post TokenAutoComplete
The code which I'm posting is initial code you can start builting control with..
I used RichTextBlock and Textbox. If you put these two controls in WrapPanel inside the Gridview. You might get similar control which you wanted but I haven't tried it.
<RichTextBlock x:Name="tokenblock">
<Paragraph>
</Paragraph>
</RichTextBlock>
<TextBox TextChanged="TextBox_TextChanged"/>
Code behind is like this
private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
{
string text = (sender as TextBox).Text;
if (text.Contains(';'))
{
Paragraph para;
text = text.Substring(0, text.LastIndexOf(';'));
if (tokenblock.Blocks.Count > 0)
para = tokenblock.Blocks[0] as Paragraph;
else
para = new Paragraph();
InlineUIContainer inline = new InlineUIContainer();
Border br = new Border();
br.Background = new SolidColorBrush(Colors.Gray);
br.CornerRadius = new CornerRadius(10);
TextBlock tb = new TextBlock();
br.MinWidth = 70;
br.MaxWidth = 150;
tb.Text = text;
tb.TextWrapping = TextWrapping.Wrap;
tb.Margin =new Thickness(10, 10, 10, 10);
br.Child = tb;
inline.Child = br;
para.Inlines.Add(inline);
(sender as TextBox).Text = "";
}
//below codes I haven't tried
<GridView x:Name="myGridView" IsItemClickEnabled="True">
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<ItemsWrapGrid Orientation="Horizontal" MaximumRowsOrColumns="5"/>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
//here you have to put RichTextBlock and textbox as two gridview items

How can I add button to top right corner of a Dialog In libgdx?

I want to add close button to top right corner of a dialog box.
I tried using setbounds with addactor and just add and setposition with setsize and addactor, but nothing works. I know that dialog works with table layout, it has a table for content and for buttons. I don't want to use this layout and put the button outside this layout like on the border of the dialog.
How can I do it?
This is how it should be:
The easiest solution I could come up with now, is to use negative padding for your button to move it "outside" of it's cell.
Button closeButton = new TextButton("X", skin, "default");
getTitleTable().add(closeButton).size(60, 40).padRight(-30).padTop(-20);
With this padding hack you have the problem, that the button will be outside of your Dialog, and by default, Window checks the bounds of your window when it performs Actor.hit(...) evaluation.
We need to disable clipping for that reason, but the rendering of the window depends on it. That's why we use another hack to enable it, just for the rendering:
#Override
public void draw(Batch batch, float parentAlpha) {
setClip(true);
super.draw(batch, parentAlpha);
setClip(false);
}
Do this:
private Stage stage;
private Window window;
private Table table;
#Override
public void show() {
table = new Table();
table.setSize(Gdx.graphics.getWidth() / 2
, Gdx.graphics.getHeight() / 5);
window = new Window("", skin);
window.setSize(table.getWidth(), table.getHeight());
Button btnWindow = new Button(skin, "close");
btnWindow.addListener(new ClickListener() {
#Override
public void clicked(InputEvent event, float x, float y) {
window.setVisible(false);
}
});
window.addActor(btnWindow);
btnWindow.setSize(50, 50);
btnWindow.setPosition(window.getWidth() - btnWindow.getWidth()
, window.getHeight() - btnWindow.getHeight());
table.addActor(window);
window.setModal(true);
table.setPosition(Gdx.graphics.getWidth() / 2 - window.getWidth() / 2
, Gdx.graphics.getHeight() / 2 - window.getHeight() / 2 +
100);
window.addAction(Actions.sequence(Actions.alpha(0)
, Actions.fadeIn(.1f)
, Actions.moveTo(+50, +50, 1)));
stage.addActor(table);
}
I had a similar problem. After a bit of searching this thread helped me.
Basically to tell the alignment of the actors inside a table, and to tell the alignment of the table itself are two separate things. Setting the alignment of the table top top-left would produce the desired behavior.
table = new Table();
table.setFillParent(true);
table.setSkin(usedSkin);
table.setDebug(true);
table.top().left();
stage.addActor(table);
table.add(exitBtn);

Android Spannable dismiss after editing

I am implementing mentions as in twitter #username. But mentions can't be typed, only selected from MultiAutoCompleteTextView.
I am creating spannable with blue text color on treminateToken
Spannable sp = new SpannableString(text + " ");
sp.setSpan(new ForegroundColorSpan(Color.BLUE), 0, text.length(), Spannable.SPAN_INCLUSIVE_INCLUSIVE);
But the problem is that user can edit this text.
How to make this snap non editable? To delete whole span when user press backspace?
Or at least change color back to black if it have been edited.
Try this
Pass your string to this below method using key listener of your editext
public void displayText(String s)
{
String ss[]=s.split(",");
for(int i=0;i<ss.length;i++)
{
final SpannableStringBuilder sb = new SpannableStringBuilder();
TextView tv = createContactTextView(ss[i]);
BitmapDrawable bd = (BitmapDrawable) GlobalMethods.convertViewToDrawable(tv);
bd.setBounds(0, 0, bd.getIntrinsicWidth(),bd.getIntrinsicHeight());
sb.append(ss[i] + ",");
sb.setSpan(new ImageSpan(bd), sb.length()-(ss[i].length()+1), sb.length()-1,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
contact.setText(sb);//your edit text here
}
}
set text style
public TextView createContactTextView(String text)
{
TextView tv = new TextView(this);
tv.setText(text);
tv.setTextSize(25);
tv.setBackgroundResource(R.drawable.design);
return tv;
}
Output:
if the user try to delete the text it delete the whole text

Removing menu in MFC

In MFC how to remove a menu-item of POPUP type. RemoveMenu() either take ID or position. Since, there is no ID for POPUP menu, option left is by using position.
But I am not getting how and where I can call RemoveMenu().
File Edit Test
Test_submenu_1
Test_submenu_2
Test_submenu_3 > submenu_3_item_1
Test_submenu_4
Test_submenu_5
I want to remove Test_submenu_3? I am not getting how do find CMenu object for Test so that I can call RemoveMenu() by passing position "2" for submenu_3_item_1.
Any suggestion for doing this will be greatly appreciated.
Thanks!
You cannot use LoadMenu, since this function does just that.
After modifying loaded menu it is killed when menu object used to load it goes out of scope. You have to modify menu that is currently used.
Your menu is a popup part of the main menu, second in position. It contains 5 items and second one is another popup. To my understanding, you want to remove this item and popup of this item.
To make it work you will have to ask main window for the current menu:
CMenu* pMenu = GetMenu(); // get the main menu
CMenu* pPopupMenu = pMenu->GetSubMenu(2);//(Test menu with item....)
pPopupMenu->RemoveMenu(2, MF_BYPOSITION);
Of course, this code is from the main frame. If you want to use it elsewhere, you will have to access all using pointer to the main frame.
Try the below. You get the Test sub-menu first (index 2), then once you have that you tell it to remove its Test_submenu_3 submenu by position (also 2).
CMenu topMenu;
topMenu.LoadMenu(IDR_YOUR_MENU);
CMenu& testSubMenu = *topMenu.GetSubMenu(2);
testSubMenu.RemoveMenu(2,MF_BYPOSITION);
'Test' is the 3rd menu item (by position) on the top level menu. It's just been rendered horizontally rather than vertically. Assuming you have a handle to the top level menu use the same code you'd use to the get the sub menus as you would to get the 'Test' menu.
You can use this below code to remove the submenu, by comparing name
bool RemoveSubmenu(CMenu * pMenu) {
for (int pos = 0; pos < pMenu->GetMenuItemCount(); pos++) {
wchar_t *name = new wchar_t[mf.cch + 1];
MENUITEMINFO mf;
ZeroMemory(&mf, sizeof(mf));
mf.cbSize = sizeof(mf);
mf.fMask = MIIM_SUBMENU | MIIM_FTYPE | MIIM_STRING;
mf.fType = MIIM_STRING;
mf.dwTypeData = NULL;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf))
break;
if (mf.hSubMenu != NULL){
mf.fMask = MIIM_TYPE;
mf.fType = MFT_STRING;
++mf.cch;
mf.dwTypeData = (LPSTR)name;
if (!GetMenuItemInfo(pMenu->m_hMenu, pos, TRUE, &mf)){
bRet = false;
break;
}
//
// compare sub menu name (i.e mf.dwTypeData) here, do the required
// modifications
//
pMenu->RemoveMenu(pos, MF_BYPOSITION);
bRet = true;
break;
}
}
}

Resources