I was trying to set the max length of an EditText, but I didn't get success.
I tried like this:
a.setFilters (new InputFilter[] { new InputFilter.LengthFilter (a.Length) });
and I get some errors ( Not at a.Length ).
and like this:
a.setMaxLength ( a.Lenght);
and still some errors.
I think that I forget some headers but that's just a guess.
Metion that I use Xamarin. Thank you in advance.
If you using c# best if you try it like this
MyEditText.SetFilters( new IInputFilter[] { new InputFilterLengthFilter(10) } );
Try
TextView a = new TextView(...);
InputFilter[] filter = new InputFilter[1];
filter[1] = new InputFilter.LengthFilter(10);
a.setFilters (filter);
or Use this in your xml:
android:maxLength="20"
editText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(12) });
OR
EditText youredittext = new EditText(this);
int maxLength = 10;
InputFilter[] fArray = new InputFilter[1];
fArray[0] = new InputFilter.LengthFilter(maxLength);
youredittext.setFilters(fArray);
Related
I am trying to make a TextBox locked by using OpenXML SDK. I've tried this method but the TextBox NoTextEdit is not working.
public DocumentFormat.OpenXml.Presentation.Shape GenerateShape(string StrText)
{
DocumentFormat.OpenXml.Presentation.Shape shape1 = new DocumentFormat.OpenXml.Presentation.Shape();
DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties nonVisualShapeProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeProperties();
DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties nonVisualDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualDrawingProperties() { Id = (UInt32Value)3U, Name = "ID",Hidden=true ,Description="Do not Remove" ,MCAttributes=null };
DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties nonVisualShapeDrawingProperties1 = new DocumentFormat.OpenXml.Presentation.NonVisualShapeDrawingProperties();
Drawing.ShapeLocks shapeLocks1 = new Drawing.ShapeLocks() { NoTextEdit = true, NoGrouping = true,NoMove=true,NoSelection=true,NoEditPoints=true ,NoAdjustHandles=true ,NoRotation=true,NoChangeArrowheads=true,NoChangeAspect=true,NoChangeShapeType=true,NoResize=true};
nonVisualShapeDrawingProperties1.Append(shapeLocks1);
ApplicationNonVisualDrawingProperties applicationNonVisualDrawingProperties1 = new ApplicationNonVisualDrawingProperties();
PlaceholderShape placeholderShape1 = new PlaceholderShape() { Type = PlaceholderValues.SubTitle, Index = (UInt32Value)1U };
applicationNonVisualDrawingProperties1.Append(placeholderShape1);
nonVisualShapeProperties1.Append(nonVisualDrawingProperties1);
nonVisualShapeProperties1.Append(nonVisualShapeDrawingProperties1);
nonVisualShapeProperties1.Append(applicationNonVisualDrawingProperties1);
DocumentFormat.OpenXml.Presentation.ShapeProperties shapeProperties1 = new DocumentFormat.OpenXml.Presentation.ShapeProperties();
DocumentFormat.OpenXml.Presentation.TextBody textBody1 = new DocumentFormat.OpenXml.Presentation.TextBody();
Drawing.BodyProperties bodyProperties1 = new Drawing.BodyProperties();
Drawing.ListStyle listStyle1 = new Drawing.ListStyle();
Drawing.TextShape shp = new Drawing.TextShape();
Drawing.Paragraph paragraph1 = new Drawing.Paragraph();
Drawing.EndParagraphRunProperties endParagraphRunProperties1 = new Drawing.EndParagraphRunProperties() { Language = "en-US" ,Dirty=false };
paragraph1.Append(GenerateRun(StrText));
paragraph1.Append(endParagraphRunProperties1);
textBody1.Append(bodyProperties1);
textBody1.Append(listStyle1);
textBody1.Append(paragraph1);
shape1.Append(nonVisualShapeProperties1);
shape1.Append(shapeProperties1);
shape1.Append(textBody1);
return shape1;
}
public Drawing.Run GenerateRun(string StrText)
{
Drawing.Run run1 = new Drawing.Run();
Drawing.RunProperties runProperties1 = new Drawing.RunProperties() { Language = "en-US", Dirty = false };
runProperties1.SetAttribute(new OpenXmlAttribute("", "smtClean", "", "0"));
Drawing.Text text1 = new Drawing.Text();
text1.Text = StrText;
Drawing.SolidFill solidFill2 = new Drawing.SolidFill();
Drawing.SchemeColor schemeColor = new Drawing.SchemeColor();
string y = System.Drawing.Color.Transparent.ToArgb().ToString("X");
Drawing.RgbColorModelHex rgbColorModelHex2 = new Drawing.RgbColorModelHex() { Val = "FFFFFF" };//Set Font-Color to Blue (Hex "0070C0").
solidFill2.Append(rgbColorModelHex2);
runProperties1.Append(solidFill2);
Color color = new Color() { Val = "365F91", ThemeColor = ThemeColorValues.Accent1, ThemeShade = "BF" };
run1.Append(runProperties1);
run1.Append(text1);
return run1;
}
Everything works fine except editing. Still the user can edit the TextBox values by double clicking it. How can I avoid this ?
Is there any permanent solution to prevent editing ? Please help me to find a better solution.
Thanks in advance
By researching and communications with the MVP team I've pointed out that there is no way to Protect the TextBox from editing.
As Cindy Meister mentioned in the comments,
Are you able to do it in the PowerPoint application user interface? If not, then Open XML cannot do it... If yes, you can.
If you do not want to text to be changed , Just change it as image then lock that by using NoSelection=true/1 and NoMove=true/1 properties. If you enable these properties the user can't either delete nor change it's position.
For your ref: https://answers.microsoft.com/en-us/msoffice/forum/msoffice_powerpoint-mso_windows8-mso_2016/shape-lock-is-not-working/c1705b55-d2aa-4adb-b538-574ed2fc8eca?tm=1579265435636&page=1&rtAction=1579495439869
I'm new to C# programming and I have a function involving FontFamily. The code seems to work fine but I wanted it written in a more concise manner.
I searched online but seems unable to get the right solution. The following code is what I currently have.
public FontFamily[] FontFamilyExt()
{
FontFamily[] f =
{new FontFamily(_fnt[0]),
new FontFamily(_fnt[1]),
new FontFamily(_fnt[2]),
new FontFamily(_fnt[3]),
new FontFamily(_fnt[4]),
new FontFamily(_fnt[5]),
new FontFamily(_fnt[6]),
new FontFamily(_fnt[7]),
new FontFamily(_fnt[8]),
new FontFamily(_fnt[9]),
new FontFamily(_fnt[10]),
new FontFamily(_fnt[11]),
new FontFamily(_fnt[12]),
new FontFamily(_fnt[13]),
new FontFamily(_fnt[14]),
new FontFamily(_fnt[15]),
new FontFamily(_fnt[16]),
new FontFamily(_fnt[17]),
new FontFamily(_fnt[18]),
new FontFamily(_fnt[19]),
new FontFamily(_fnt[20]),
new FontFamily(_fnt[21]),
new FontFamily(_fnt[22]),
new FontFamily(_fnt[23]),
new FontFamily(_fnt[24]),
new FontFamily(_fnt[25]),
new FontFamily(_fnt[26]),
new FontFamily(_fnt[27]),
new FontFamily(_fnt[28]),
new FontFamily(_fnt[29]),
new FontFamily(_fnt[30]),
new FontFamily(_fnt[31])
};
return f;
}
I am looking for something that works similarly but uses less codes. Thank you in advance.
You could use a loop as recommended. You could also use Enumerable.Range, which basically creates a loop under the covers, but will put the code into one line. Something like:
using System.Linq;
public FontFamily[] FontFamilyExt()
{
return Enumerable.Range(0, 32).Select(x => new FontFamily(_fnt[x])).ToArray();
}
You can try this:
public FontFamily[] FontFamilyExt()
{
FontFamily[] f = new FontFamily[32];
for ( int index = 0; index <= 31; index++ )
f[index] = new FontFamily(_fnt[index]);
return f;
}
I have an Amazon EC2 instance and I need to be able to create an AMI (image) from it programmatically. I'm trying the following:
CreateImageRequest rq = new CreateImageRequest();
rq.InstanceId = myInstanceID;
rq.Name = instance.KeyName;
rq.Description = "stam";
rq.NoReboot = true;
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
try
{
imageResp = ec2.CreateImage(rq);
}
catch (AmazonServiceException ase)
{
MessageBox.Show(ase.Message);
}
The result is always an AmazonServiceException saying that there is a NameResolutionFailure.
How do I overcome this? I tried different possible "name" possibilities but cannot find the right one.
string amiID = ConfigurationManager.AppSettings[AmazonConstants.AwsImageId];
string keyPairName = ConfigurationManager.AppSettings[AmazonConstants.AwsKeyPair];
List<string> groups = new List<string>() { ConfigurationManager.AppSettings[AmazonConstants.AwsSecurityGroupId] };
var launchRequest = new RunInstancesRequest()
{
ImageId = amiID,
InstanceType = ConfigurationManager.AppSettings[AmazonConstants.AwsInstanceType],
MinCount = 1,
MaxCount = 1,
KeyName = keyPairName,
SecurityGroupIds = groups,
SubnetId = ConfigurationManager.AppSettings[AmazonConstants.AwsSubnetId]
};
RunInstancesResponse runInstancesResponse = amazonEc2client.RunInstances(launchRequest);
RunInstancesResult runInstancesResult = runInstancesResponse.RunInstancesResult;
Reservation reservation = runInstancesResult.Reservation;
Problem eventually solved!
it turned out thyat some codelines were doing things which were already done already and removing this part:
IAmazonEC2 ec2;
AmazonEC2Config ec2conf = new AmazonEC2Config();
ec2 = AWSClientFactory.CreateAmazonEC2Client(ec2conf);
// CreateImageResponse imageResp;
Amazon.EC2.Model.CreateImageResponse imageResp = null;
Made things clearer and no wrong repetitions happened! Now it works!
I am trying to get the list of UserLists on the account, but I get no entries even though during debugging the TotalNumOfEntries is 17. Screen shot is attached, any ideas why I cant see what these entries are? (sorry the details of debugger came out faint)
Code:
AdwordsUserListService usrService = (AdwordsUserListService)user.GetService(AdWordsService.v201402.AdwordsUserListService);
Selector usrSelect = new Selector();
usrSelect.fields = new String[] { "Id","Name", "Size", "MembershipLifeSpan" };
//Use predicates for filtering, if needed, later.
//Predicate usrPredicate = new Predicate();
//usrPredicate.field = "Name";
//usrPredicate.#operator = PredicateOperator.STARTS_WITH;
//usrPredicate.values = new string[] { "Poly" };
//usrSelect.predicates = new Predicate[] { usrPredicate };
usrSelect.paging = new Paging();
usrSelect.ordering = new OrderBy[] { new OrderBy() { field="Name",sortOrder=SortOrder.ASCENDING} };
UserListPage userListResult = usrService.get(usrSelect);
if (userListResult.entries != null)
{
return "Yay!";
}
Found my problem, I specified paging but didn't specify how many entries, adding this line fixed the problem.
usrSelect.paging.numberResults = 20;
I have been trying to bring back 20 results of images using the Bing API. Here's the code:
SearchRequest request = new SearchRequest();
request.AppId = APPID;
request.Query = HttpUtility.HtmlEncode(searchQuery);
request.Sources = new SourceType[] { SourceType.Image };
request.Image = new ImageRequest();
request.Image.Count = 20;
request.Image.Filters = new string[1] { "Size:Medium" };
Now everything on here works, including the Image.Filters property. Just not the Count property. Is there a known bug or am I just missing something here?
I'm not sure really sure about this but I think you are missing setting CountSpecified property. Try this
request.Image = new ImageRequest();
request.Image.Offset = 0;
request.Image.Count = 20;
request.Image.CountSpecified = true;
request.Image.Filters = new string[1] { "Size:Medium" };